Java 平台概述
一、Java 发展简史
<mxfile>
<diagram id="java-timeline" name="Java发展里程碑">
<mxGraphModel dx="1665" dy="798" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="1200" pageHeight="800" math="0" shadow="0">
<root>
<mxCell id="0" />
<mxCell id="1" parent="0" />
<mxCell id="32" parent="1" style="rounded=0;whiteSpace=wrap;html=1;" value="" vertex="1">
<mxGeometry height="690" width="600" x="120" y="15" as="geometry" />
</mxCell>
<mxCell id="2" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;fontSize=24;fontStyle=1;fontColor=#1a365d;" value="Java 发展里程碑" vertex="1">
<mxGeometry height="40" width="300" x="260" y="30" as="geometry" />
</mxCell>
<mxCell id="3" edge="1" parent="1" style="edgeStyle=none;strokeColor=#5D7B9D;strokeWidth=4;endArrow=none;">
<mxGeometry relative="1" as="geometry">
<mxPoint x="200" y="120" as="sourcePoint" />
<mxPoint x="200" y="680" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="4" parent="1" style="ellipse;whiteSpace=wrap;html=1;fillColor=#1e3a5f;strokeColor=#1e3a5f;fontColor=#ffffff;fontStyle=1;fontSize=14;" value="1991" vertex="1">
<mxGeometry height="40" width="80" x="160" y="100" as="geometry" />
</mxCell>
<mxCell id="5" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dbeafe;strokeColor=#3b82f6;fontColor=#1e3a5f;fontSize=13;align=left;spacingLeft=10;" value="Sun 公司 James Gosling 团队启动 "Green" 项目" vertex="1">
<mxGeometry height="50" width="420" x="280" y="95" as="geometry" />
</mxCell>
<mxCell id="6" parent="1" style="ellipse;whiteSpace=wrap;html=1;fillColor=#1e3a5f;strokeColor=#1e3a5f;fontColor=#ffffff;fontStyle=1;fontSize=14;" value="1995" vertex="1">
<mxGeometry height="40" width="80" x="160" y="160" as="geometry" />
</mxCell>
<mxCell id="7" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dcfce7;strokeColor=#22c55e;fontColor=#166534;fontSize=13;align=left;spacingLeft=10;" value="Java 1.0 正式发布,"Write Once, Run Anywhere" 诞生" vertex="1">
<mxGeometry height="50" width="420" x="280" y="155" as="geometry" />
</mxCell>
<mxCell id="8" parent="1" style="ellipse;whiteSpace=wrap;html=1;fillColor=#1e3a5f;strokeColor=#1e3a5f;fontColor=#ffffff;fontStyle=1;fontSize=14;" value="2004" vertex="1">
<mxGeometry height="40" width="80" x="160" y="220" as="geometry" />
</mxCell>
<mxCell id="9" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fef3c7;strokeColor=#f59e0b;fontColor=#92400e;fontSize=13;align=left;spacingLeft=10;" value="Java 5.0 发布(泛型、注解、枚举、自动装箱等重大更新)" vertex="1">
<mxGeometry height="50" width="420" x="280" y="215" as="geometry" />
</mxCell>
<mxCell id="10" parent="1" style="ellipse;whiteSpace=wrap;html=1;fillColor=#1e3a5f;strokeColor=#1e3a5f;fontColor=#ffffff;fontStyle=1;fontSize=14;" value="2006" vertex="1">
<mxGeometry height="40" width="80" x="160" y="280" as="geometry" />
</mxCell>
<mxCell id="11" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dbeafe;strokeColor=#3b82f6;fontColor=#1e3a5f;fontSize=13;align=left;spacingLeft=10;" value="Sun 开源 Java,诞生 OpenJDK" vertex="1">
<mxGeometry height="50" width="420" x="280" y="275" as="geometry" />
</mxCell>
<mxCell id="12" parent="1" style="ellipse;whiteSpace=wrap;html=1;fillColor=#1e3a5f;strokeColor=#1e3a5f;fontColor=#ffffff;fontStyle=1;fontSize=14;" value="2009" vertex="1">
<mxGeometry height="40" width="80" x="160" y="340" as="geometry" />
</mxCell>
<mxCell id="13" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fee2e2;strokeColor=#ef4444;fontColor=#991b1b;fontSize=13;align=left;spacingLeft=10;" value="Oracle 收购 Sun,获得 Java 所有权" vertex="1">
<mxGeometry height="50" width="420" x="280" y="335" as="geometry" />
</mxCell>
<mxCell id="14" parent="1" style="ellipse;whiteSpace=wrap;html=1;fillColor=#1e3a5f;strokeColor=#1e3a5f;fontColor=#ffffff;fontStyle=1;fontSize=14;" value="2014" vertex="1">
<mxGeometry height="40" width="80" x="160" y="400" as="geometry" />
</mxCell>
<mxCell id="15" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dcfce7;strokeColor=#22c55e;fontColor=#166534;fontSize=13;align=left;spacingLeft=10;" value="Java 8 发布(Lambda、Stream API,目前仍广泛使用)" vertex="1">
<mxGeometry height="50" width="420" x="280" y="395" as="geometry" />
</mxCell>
<mxCell id="16" parent="1" style="ellipse;whiteSpace=wrap;html=1;fillColor=#1e3a5f;strokeColor=#1e3a5f;fontColor=#ffffff;fontStyle=1;fontSize=14;" value="2017" vertex="1">
<mxGeometry height="40" width="80" x="160" y="460" as="geometry" />
</mxCell>
<mxCell id="17" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fef3c7;strokeColor=#f59e0b;fontColor=#92400e;fontSize=13;align=left;spacingLeft=10;" value="Java 9 发布,开启 6 个月发布周期" vertex="1">
<mxGeometry height="50" width="420" x="280" y="455" as="geometry" />
</mxCell>
<mxCell id="18" parent="1" style="ellipse;whiteSpace=wrap;html=1;fillColor=#1e3a5f;strokeColor=#1e3a5f;fontColor=#ffffff;fontStyle=1;fontSize=14;" value="2021" vertex="1">
<mxGeometry height="40" width="80" x="160" y="520" as="geometry" />
</mxCell>
<mxCell id="19" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dbeafe;strokeColor=#3b82f6;fontColor=#1e3a5f;fontSize=13;align=left;spacingLeft=10;" value="Java 17 LTS 发布(目前主流长期支持版本)" vertex="1">
<mxGeometry height="50" width="420" x="280" y="515" as="geometry" />
</mxCell>
<mxCell id="20" parent="1" style="ellipse;whiteSpace=wrap;html=1;fillColor=#1e3a5f;strokeColor=#1e3a5f;fontColor=#ffffff;fontStyle=1;fontSize=14;" value="2023" vertex="1">
<mxGeometry height="40" width="80" x="160" y="580" as="geometry" />
</mxCell>
<mxCell id="21" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dcfce7;strokeColor=#22c55e;fontColor=#166534;fontSize=13;align=left;spacingLeft=10;" value="Java 21 LTS 发布(虚拟线程正式版、模式匹配增强)" vertex="1">
<mxGeometry height="50" width="420" x="280" y="575" as="geometry" />
</mxCell>
<mxCell id="22" edge="1" parent="1" style="edgeStyle=none;strokeColor=#94a3b8;strokeWidth=1;endArrow=none;dashed=1;">
<mxGeometry relative="1" as="geometry">
<mxPoint x="240" y="120" as="sourcePoint" />
<mxPoint x="280" y="120" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="23" edge="1" parent="1" style="edgeStyle=none;strokeColor=#94a3b8;strokeWidth=1;endArrow=none;dashed=1;">
<mxGeometry relative="1" as="geometry">
<mxPoint x="240" y="180" as="sourcePoint" />
<mxPoint x="280" y="180" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="24" edge="1" parent="1" style="edgeStyle=none;strokeColor=#94a3b8;strokeWidth=1;endArrow=none;dashed=1;">
<mxGeometry relative="1" as="geometry">
<mxPoint x="240" y="240" as="sourcePoint" />
<mxPoint x="280" y="240" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="25" edge="1" parent="1" style="edgeStyle=none;strokeColor=#94a3b8;strokeWidth=1;endArrow=none;dashed=1;">
<mxGeometry relative="1" as="geometry">
<mxPoint x="240" y="300" as="sourcePoint" />
<mxPoint x="280" y="300" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="26" edge="1" parent="1" style="edgeStyle=none;strokeColor=#94a3b8;strokeWidth=1;endArrow=none;dashed=1;">
<mxGeometry relative="1" as="geometry">
<mxPoint x="240" y="360" as="sourcePoint" />
<mxPoint x="280" y="360" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="27" edge="1" parent="1" style="edgeStyle=none;strokeColor=#94a3b8;strokeWidth=1;endArrow=none;dashed=1;">
<mxGeometry relative="1" as="geometry">
<mxPoint x="240" y="420" as="sourcePoint" />
<mxPoint x="280" y="420" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="28" edge="1" parent="1" style="edgeStyle=none;strokeColor=#94a3b8;strokeWidth=1;endArrow=none;dashed=1;">
<mxGeometry relative="1" as="geometry">
<mxPoint x="240" y="480" as="sourcePoint" />
<mxPoint x="280" y="480" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="29" edge="1" parent="1" style="edgeStyle=none;strokeColor=#94a3b8;strokeWidth=1;endArrow=none;dashed=1;">
<mxGeometry relative="1" as="geometry">
<mxPoint x="240" y="540" as="sourcePoint" />
<mxPoint x="280" y="540" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="30" edge="1" parent="1" style="edgeStyle=none;strokeColor=#94a3b8;strokeWidth=1;endArrow=none;dashed=1;">
<mxGeometry relative="1" as="geometry">
<mxPoint x="240" y="600" as="sourcePoint" />
<mxPoint x="280" y="600" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="31" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;fontSize=28;" value="☕" vertex="1">
<mxGeometry height="40" width="40" x="180" y="640" as="geometry" />
</mxCell>
</root>
</mxGraphModel>
</diagram>
</mxfile>
💡 LTS (Long-Term Support):长期支持版本,Oracle 提供至少 8 年的更新支持。目前的 LTS 版本1有:Java 8、11、17、21
二、Java 的核心特性
2.1 整体特性图
<mxfile>
<diagram id="java-core-features" name="Java核心特性">
<mxGraphModel dx="900" dy="600" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="1100" pageHeight="700">
<root>
<mxCell id="0" />
<mxCell id="1" parent="0" />
<mxCell id="2" value="Java 核心特性" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#1e3a5f;strokeColor=#1e3a5f;fontColor=#ffffff;fontStyle=1;fontSize=18;shadow=1;" vertex="1" parent="1">
<mxGeometry x="440" y="40" width="180" height="50" as="geometry" />
</mxCell>
<mxCell id="3" style="edgeStyle=orthogonalEdgeStyle;strokeColor=#5D7B9D;strokeWidth=2;endArrow=none;" edge="1" parent="1" source="2">
<mxGeometry relative="1" as="geometry">
<mxPoint x="530" y="130" as="targetPoint" /></mxGeometry>
</mxCell>
<mxCell id="4" style="edgeStyle=none;strokeColor=#5D7B9D;strokeWidth=2;endArrow=none;" edge="1" parent="1">
<mxGeometry relative="1" as="geometry">
<mxPoint x="110" y="130" as="sourcePoint" />
<mxPoint x="950" y="130" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="5" style="edgeStyle=none;strokeColor=#5D7B9D;strokeWidth=2;endArrow=classic;" edge="1" parent="1">
<mxGeometry relative="1" as="geometry">
<mxPoint x="110" y="130" as="sourcePoint" />
<mxPoint x="110" y="170" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="6" style="edgeStyle=none;strokeColor=#5D7B9D;strokeWidth=2;endArrow=classic;" edge="1" parent="1">
<mxGeometry relative="1" as="geometry">
<mxPoint x="320" y="130" as="sourcePoint" />
<mxPoint x="320" y="170" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="7" style="edgeStyle=none;strokeColor=#5D7B9D;strokeWidth=2;endArrow=classic;" edge="1" parent="1">
<mxGeometry relative="1" as="geometry">
<mxPoint x="530" y="130" as="sourcePoint" />
<mxPoint x="530" y="170" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="8" style="edgeStyle=none;strokeColor=#5D7B9D;strokeWidth=2;endArrow=classic;" edge="1" parent="1">
<mxGeometry relative="1" as="geometry">
<mxPoint x="740" y="130" as="sourcePoint" />
<mxPoint x="740" y="170" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="9" style="edgeStyle=none;strokeColor=#5D7B9D;strokeWidth=2;endArrow=classic;" edge="1" parent="1">
<mxGeometry relative="1" as="geometry">
<mxPoint x="950" y="130" as="sourcePoint" />
<mxPoint x="950" y="170" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="10" value="面向对象" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dbeafe;strokeColor=#3b82f6;fontColor=#1e3a5f;fontStyle=1;fontSize=14;shadow=1;" vertex="1" parent="1">
<mxGeometry x="40" y="170" width="140" height="50" as="geometry" />
</mxCell>
<mxCell id="11" value="跨平台" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dcfce7;strokeColor=#22c55e;fontColor=#166534;fontStyle=1;fontSize=14;shadow=1;" vertex="1" parent="1">
<mxGeometry x="250" y="170" width="140" height="50" as="geometry" />
</mxCell>
<mxCell id="12" value="多线程" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fef3c7;strokeColor=#f59e0b;fontColor=#92400e;fontStyle=1;fontSize=14;shadow=1;" vertex="1" parent="1">
<mxGeometry x="460" y="170" width="140" height="50" as="geometry" />
</mxCell>
<mxCell id="13" value="自动GC" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fce7f3;strokeColor=#ec4899;fontColor=#9d174d;fontStyle=1;fontSize=14;shadow=1;" vertex="1" parent="1">
<mxGeometry x="670" y="170" width="140" height="50" as="geometry" />
</mxCell>
<mxCell id="14" value="安全性" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#e0e7ff;strokeColor=#6366f1;fontColor=#3730a3;fontStyle=1;fontSize=14;shadow=1;" vertex="1" parent="1">
<mxGeometry x="880" y="170" width="140" height="50" as="geometry" />
</mxCell>
<mxCell id="15" style="edgeStyle=none;strokeColor=#3b82f6;strokeWidth=2;endArrow=classic;" edge="1" parent="1" source="10" target="16">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="16" value="封装
继承
多态" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#eff6ff;strokeColor=#bfdbfe;fontColor=#1e40af;fontSize=12;align=center;" vertex="1" parent="1">
<mxGeometry x="40" y="280" width="140" height="70" as="geometry" />
</mxCell>
<mxCell id="17" style="edgeStyle=none;strokeColor=#22c55e;strokeWidth=2;endArrow=classic;" edge="1" parent="1" source="11" target="18">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="18" value="JVM实现
一次编写
到处运行" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#f0fdf4;strokeColor=#bbf7d0;fontColor=#166534;fontSize=12;align=center;" vertex="1" parent="1">
<mxGeometry x="250" y="280" width="140" height="70" as="geometry" />
</mxCell>
<mxCell id="19" style="edgeStyle=none;strokeColor=#f59e0b;strokeWidth=2;endArrow=classic;" edge="1" parent="1" source="12" target="20">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="20" value="原生支持
Thread类
并发包" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fffbeb;strokeColor=#fde68a;fontColor=#92400e;fontSize=12;align=center;" vertex="1" parent="1">
<mxGeometry x="460" y="280" width="140" height="70" as="geometry" />
</mxCell>
<mxCell id="21" style="edgeStyle=none;strokeColor=#ec4899;strokeWidth=2;endArrow=classic;" edge="1" parent="1" source="13" target="22">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="22" value="垃圾回收
无需手动
释放内存" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fdf2f8;strokeColor=#fbcfe8;fontColor=#9d174d;fontSize=12;align=center;" vertex="1" parent="1">
<mxGeometry x="670" y="280" width="140" height="70" as="geometry" />
</mxCell>
<mxCell id="23" style="edgeStyle=none;strokeColor=#6366f1;strokeWidth=2;endArrow=classic;" edge="1" parent="1" source="14" target="24">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="24" value="类型检查
访问控制
字节码验证" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#eef2ff;strokeColor=#c7d2fe;fontColor=#3730a3;fontSize=12;align=center;" vertex="1" parent="1">
<mxGeometry x="880" y="280" width="140" height="70" as="geometry" />
</mxCell>
<mxCell id="25" value="☕" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;fontSize=24;" vertex="1" parent="1">
<mxGeometry x="625" y="40" width="40" height="50" as="geometry" />
</mxCell>
</root>
</mxGraphModel>
</diagram>
</mxfile>
2.2 面向对象(OOP)
Java 是纯面向对象语言,支持三大核心特性:
// ======================== 封装 ========================
// 将数据和行为包装在一起,隐藏内部实现细节
public class BankAccount {
private double balance; // 私有属性,外部无法直接访问
public void deposit(double amount) { // 公开方法作为访问入口
if (amount > 0) {
this.balance += amount;
}
}
public double getBalance() { // 只读访问
return this.balance;
}
}
// ======================== 继承 ========================
// 子类复用父类的属性和方法,实现代码重用
public class Animal {
protected String name;
public void eat() {
System.out.println(name + " is eating");
}
}
public class Dog extends Animal { // Dog 继承 Animal
public void bark() {
System.out.println(name + " is barking");
}
}
// ======================== 多态 ========================
// 同一接口,不同实现;父类引用指向子类对象
public class Cat extends Animal {
@Override
public void eat() {
System.out.println(name + " eats fish"); // 重写父类方法
}
}
// 多态的体现
Animal animal1 = new Dog(); // 父类引用 → 子类对象
Animal animal2 = new Cat();
animal1.eat(); // 调用 Dog 的 eat(如果重写了)
animal2.eat(); // 调用 Cat 的 eat
多态的底层机制:
<mxfile>
<diagram id="dynamic-binding" name="方法调用过程(动态绑定)">
<mxGraphModel dx="900" dy="650" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="900" pageHeight="700">
<root>
<mxCell id="0" />
<mxCell id="1" parent="0" />
<mxCell id="2" value="方法调用过程(动态绑定)" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#1e3a5f;strokeColor=#1e3a5f;fontColor=#ffffff;fontStyle=1;fontSize=18;verticalAlign=middle;" vertex="1" parent="1">
<mxGeometry x="40" y="30" width="820" height="50" as="geometry" />
</mxCell>
<mxCell id="3" value="" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#f8fafc;strokeColor=#cbd5e1;strokeWidth=2;" vertex="1" parent="1">
<mxGeometry x="40" y="80" width="820" height="560" as="geometry" />
</mxCell>
<mxCell id="4" value="代码示例" style="text;html=1;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;fontSize=14;fontStyle=1;fontColor=#475569;" vertex="1" parent="1">
<mxGeometry x="60" y="100" width="100" height="30" as="geometry" />
</mxCell>
<mxCell id="5" value="Animal animal = new Cat();
animal.eat();" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#1e293b;strokeColor=#334155;fontColor=#e2e8f0;fontSize=14;fontFamily=Consolas;align=left;spacingLeft=15;spacingTop=5;spacingBottom=5;" vertex="1" parent="1">
<mxGeometry x="60" y="130" width="780" height="60" as="geometry" />
</mxCell>
<mxCell id="6" value="执行流程" style="text;html=1;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;fontSize=14;fontStyle=1;fontColor=#475569;" vertex="1" parent="1">
<mxGeometry x="60" y="210" width="100" height="30" as="geometry" />
</mxCell>
<mxCell id="7" value="1" style="ellipse;whiteSpace=wrap;html=1;fillColor=#3b82f6;strokeColor=#3b82f6;fontColor=#ffffff;fontStyle=1;fontSize=14;" vertex="1" parent="1">
<mxGeometry x="60" y="250" width="30" height="30" as="geometry" />
</mxCell>
<mxCell id="8" value="编译期" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dbeafe;strokeColor=#3b82f6;fontColor=#1e40af;fontStyle=1;fontSize=13;" vertex="1" parent="1">
<mxGeometry x="100" y="247" width="70" height="36" as="geometry" />
</mxCell>
<mxCell id="9" value="编译器检查 Animal 类是否有 eat() 方法" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#eff6ff;strokeColor=#bfdbfe;fontColor=#1e3a5f;fontSize=13;align=left;spacingLeft=10;" vertex="1" parent="1">
<mxGeometry x="180" y="247" width="300" height="36" as="geometry" />
</mxCell>
<mxCell id="10" value="✓" style="text;html=1;strokeColor=none;fillColor=#dcfce7;align=center;verticalAlign=middle;fontSize=18;fontStyle=1;fontColor=#16a34a;rounded=1;" vertex="1" parent="1">
<mxGeometry x="490" y="250" width="40" height="30" as="geometry" />
</mxCell>
<mxCell id="11" value="2" style="ellipse;whiteSpace=wrap;html=1;fillColor=#f59e0b;strokeColor=#f59e0b;fontColor=#ffffff;fontStyle=1;fontSize=14;" vertex="1" parent="1">
<mxGeometry x="60" y="300" width="30" height="30" as="geometry" />
</mxCell>
<mxCell id="12" value="运行期" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fef3c7;strokeColor=#f59e0b;fontColor=#92400e;fontStyle=1;fontSize=13;" vertex="1" parent="1">
<mxGeometry x="100" y="297" width="70" height="36" as="geometry" />
</mxCell>
<mxCell id="13" value="JVM 查看 animal 实际指向的对象类型" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fffbeb;strokeColor=#fde68a;fontColor=#78350f;fontSize=13;align=left;spacingLeft=10;" vertex="1" parent="1">
<mxGeometry x="180" y="297" width="280" height="36" as="geometry" />
</mxCell>
<mxCell id="14" style="edgeStyle=orthogonalEdgeStyle;strokeColor=#f59e0b;strokeWidth=2;endArrow=classic;" edge="1" parent="1">
<mxGeometry relative="1" as="geometry">
<mxPoint x="470" y="315" as="sourcePoint" />
<mxPoint x="540" y="315" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="15" value="Cat" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fef3c7;strokeColor=#f59e0b;fontColor=#92400e;fontStyle=1;fontSize=14;" vertex="1" parent="1">
<mxGeometry x="550" y="297" width="70" height="36" as="geometry" />
</mxCell>
<mxCell id="16" value="3" style="ellipse;whiteSpace=wrap;html=1;fillColor=#22c55e;strokeColor=#22c55e;fontColor=#ffffff;fontStyle=1;fontSize=14;" vertex="1" parent="1">
<mxGeometry x="60" y="350" width="30" height="30" as="geometry" />
</mxCell>
<mxCell id="17" value="执行时" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dcfce7;strokeColor=#22c55e;fontColor=#166534;fontStyle=1;fontSize=13;" vertex="1" parent="1">
<mxGeometry x="100" y="347" width="70" height="36" as="geometry" />
</mxCell>
<mxCell id="18" value="在 Cat 的方法表中查找 eat() 并执行" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#f0fdf4;strokeColor=#bbf7d0;fontColor=#166534;fontSize=13;align=left;spacingLeft=10;" vertex="1" parent="1">
<mxGeometry x="180" y="347" width="280" height="36" as="geometry" />
</mxCell>
<mxCell id="19" value="方法表对比" style="text;html=1;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;fontSize=14;fontStyle=1;fontColor=#475569;" vertex="1" parent="1">
<mxGeometry x="60" y="410" width="100" height="30" as="geometry" />
</mxCell>
<mxCell id="20" value="Animal 方法表" style="swimlane;fontStyle=1;align=center;verticalAlign=top;childLayout=stackLayout;horizontal=1;startSize=30;horizontalStack=0;resizeParent=1;resizeParentMax=0;resizeLast=0;collapsible=0;marginBottom=0;fillColor=#e0e7ff;strokeColor=#6366f1;fontColor=#3730a3;fontSize=14;" vertex="1" parent="1">
<mxGeometry x="120" y="450" width="180" height="80" as="geometry" />
</mxCell>
<mxCell id="21" value="eat()" style="text;strokeColor=#c7d2fe;fillColor=#eef2ff;align=center;verticalAlign=middle;spacingLeft=4;spacingRight=4;overflow=hidden;rotatable=0;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;fontColor=#3730a3;fontSize=13;fontFamily=Consolas;" vertex="1" parent="20">
<mxGeometry y="30" width="180" height="50" as="geometry" />
</mxCell>
<mxCell id="22" value="Cat 方法表" style="swimlane;fontStyle=1;align=center;verticalAlign=top;childLayout=stackLayout;horizontal=1;startSize=30;horizontalStack=0;resizeParent=1;resizeParentMax=0;resizeLast=0;collapsible=0;marginBottom=0;fillColor=#dcfce7;strokeColor=#22c55e;fontColor=#166534;fontSize=14;" vertex="1" parent="1">
<mxGeometry x="450" y="450" width="180" height="80" as="geometry" />
</mxCell>
<mxCell id="23" value="eat() (重写)" style="text;strokeColor=#bbf7d0;fillColor=#f0fdf4;align=center;verticalAlign=middle;spacingLeft=4;spacingRight=4;overflow=hidden;rotatable=0;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;fontColor=#166534;fontSize=13;fontFamily=Consolas;fontStyle=1;" vertex="1" parent="22">
<mxGeometry y="30" width="180" height="50" as="geometry" />
</mxCell>
<mxCell id="24" style="edgeStyle=orthogonalEdgeStyle;strokeColor=#22c55e;strokeWidth=3;endArrow=classic;dashed=1;dashPattern=8 8;" edge="1" parent="1">
<mxGeometry relative="1" as="geometry">
<mxPoint x="300" y="505" as="sourcePoint" />
<mxPoint x="450" y="505" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="25" value="← 实际执行这个" style="text;html=1;strokeColor=none;fillColor=#fef3c7;align=center;verticalAlign=middle;fontSize=12;fontStyle=1;fontColor=#92400e;rounded=1;spacingLeft=5;spacingRight=5;" vertex="1" parent="1">
<mxGeometry x="640" y="490" width="110" height="30" as="geometry" />
</mxCell>
<mxCell id="26" value="🐱" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;fontSize=24;" vertex="1" parent="1">
<mxGeometry x="630" y="297" width="40" height="36" as="geometry" />
</mxCell>
<mxCell id="27" value="💡 关键点:编译看左边(声明类型),运行看右边(实际类型)" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fef3c7;strokeColor=#f59e0b;fontColor=#92400e;fontSize=13;fontStyle=1;align=center;" vertex="1" parent="1">
<mxGeometry x="120" y="570" width="510" height="40" as="geometry" />
</mxCell>
</root>
</mxGraphModel>
</diagram>
</mxfile>
2.3 跨平台性(Write Once, Run Anywhere)
原理图解
<mxfile>
<diagram id="java-cross-platform" name="Java跨平台原理">
<mxGraphModel dx="900" dy="700" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="900" pageHeight="750">
<root>
<mxCell id="0" />
<mxCell id="1" parent="0" />
<mxCell id="2" value="Hello.java" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dbeafe;strokeColor=#3b82f6;fontColor=#1e40af;fontStyle=1;fontSize=14;shadow=1;" vertex="1" parent="1">
<mxGeometry x="370" y="40" width="160" height="50" as="geometry" />
</mxCell>
<mxCell id="3" value="(源代码)" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;fontSize=12;fontColor=#64748b;" vertex="1" parent="1">
<mxGeometry x="370" y="85" width="160" height="20" as="geometry" />
</mxCell>
<mxCell id="4" style="edgeStyle=orthogonalEdgeStyle;strokeColor=#3b82f6;strokeWidth=2;endArrow=classic;" edge="1" parent="1" source="2" target="6">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="5" value="javac 编译" style="text;html=1;strokeColor=none;fillColor=#eff6ff;align=center;verticalAlign=middle;fontSize=12;fontColor=#3b82f6;fontStyle=1;rounded=1;" vertex="1" parent="1">
<mxGeometry x="465" y="120" width="80" height="25" as="geometry" />
</mxCell>
<mxCell id="6" value="Hello.class" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fef3c7;strokeColor=#f59e0b;fontColor=#92400e;fontStyle=1;fontSize=14;shadow=1;" vertex="1" parent="1">
<mxGeometry x="370" y="170" width="160" height="50" as="geometry" />
</mxCell>
<mxCell id="7" value="(字节码)" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;fontSize=12;fontColor=#64748b;" vertex="1" parent="1">
<mxGeometry x="370" y="215" width="80" height="20" as="geometry" />
</mxCell>
<mxCell id="8" value="平台无关 ✓" style="text;html=1;strokeColor=none;fillColor=#dcfce7;align=center;verticalAlign=middle;fontSize=11;fontColor=#16a34a;fontStyle=1;rounded=1;" vertex="1" parent="1">
<mxGeometry x="450" y="217" width="75" height="20" as="geometry" />
</mxCell>
<mxCell id="9" style="edgeStyle=orthogonalEdgeStyle;strokeColor=#64748b;strokeWidth=2;endArrow=none;" edge="1" parent="1" source="6">
<mxGeometry relative="1" as="geometry">
<mxPoint x="450" y="290" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="10" style="edgeStyle=none;strokeColor=#64748b;strokeWidth=2;endArrow=none;" edge="1" parent="1">
<mxGeometry relative="1" as="geometry">
<mxPoint x="130" y="290" as="sourcePoint" />
<mxPoint x="770" y="290" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="11" style="edgeStyle=none;strokeColor=#64748b;strokeWidth=2;endArrow=classic;" edge="1" parent="1">
<mxGeometry relative="1" as="geometry">
<mxPoint x="130" y="290" as="sourcePoint" />
<mxPoint x="130" y="330" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="12" style="edgeStyle=none;strokeColor=#64748b;strokeWidth=2;endArrow=classic;" edge="1" parent="1">
<mxGeometry relative="1" as="geometry">
<mxPoint x="450" y="290" as="sourcePoint" />
<mxPoint x="450" y="330" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="13" style="edgeStyle=none;strokeColor=#64748b;strokeWidth=2;endArrow=classic;" edge="1" parent="1">
<mxGeometry relative="1" as="geometry">
<mxPoint x="770" y="290" as="sourcePoint" />
<mxPoint x="770" y="330" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="14" value="Windows JVM" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#e0e7ff;strokeColor=#6366f1;fontColor=#3730a3;fontStyle=1;fontSize=13;shadow=1;" vertex="1" parent="1">
<mxGeometry x="50" y="330" width="160" height="50" as="geometry" />
</mxCell>
<mxCell id="15" value="Linux JVM" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fce7f3;strokeColor=#ec4899;fontColor=#9d174d;fontStyle=1;fontSize=13;shadow=1;" vertex="1" parent="1">
<mxGeometry x="370" y="330" width="160" height="50" as="geometry" />
</mxCell>
<mxCell id="16" value="macOS JVM" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dcfce7;strokeColor=#22c55e;fontColor=#166534;fontStyle=1;fontSize=13;shadow=1;" vertex="1" parent="1">
<mxGeometry x="690" y="330" width="160" height="50" as="geometry" />
</mxCell>
<mxCell id="17" style="edgeStyle=orthogonalEdgeStyle;strokeColor=#6366f1;strokeWidth=2;endArrow=classic;" edge="1" parent="1" source="14" target="20">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="18" style="edgeStyle=orthogonalEdgeStyle;strokeColor=#ec4899;strokeWidth=2;endArrow=classic;" edge="1" parent="1" source="15" target="21">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="19" style="edgeStyle=orthogonalEdgeStyle;strokeColor=#22c55e;strokeWidth=2;endArrow=classic;" edge="1" parent="1" source="16" target="22">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="20" value="Windows 机器码" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#c7d2fe;strokeColor=#6366f1;fontColor=#3730a3;fontSize=13;shadow=1;" vertex="1" parent="1">
<mxGeometry x="50" y="450" width="160" height="50" as="geometry" />
</mxCell>
<mxCell id="21" value="Linux 机器码" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fbcfe8;strokeColor=#ec4899;fontColor=#9d174d;fontSize=13;shadow=1;" vertex="1" parent="1">
<mxGeometry x="370" y="450" width="160" height="50" as="geometry" />
</mxCell>
<mxCell id="22" value="macOS 机器码" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#bbf7d0;strokeColor=#22c55e;fontColor=#166534;fontSize=13;shadow=1;" vertex="1" parent="1">
<mxGeometry x="690" y="450" width="160" height="50" as="geometry" />
</mxCell>
<mxCell id="23" value="🪟" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;fontSize=24;" vertex="1" parent="1">
<mxGeometry x="110" y="500" width="40" height="40" as="geometry" />
</mxCell>
<mxCell id="24" value="🐧" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;fontSize=24;" vertex="1" parent="1">
<mxGeometry x="430" y="500" width="40" height="40" as="geometry" />
</mxCell>
<mxCell id="25" value="🍎" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;fontSize=24;" vertex="1" parent="1">
<mxGeometry x="750" y="500" width="40" height="40" as="geometry" />
</mxCell>
<mxCell id="26" value="☕" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;fontSize=20;" vertex="1" parent="1">
<mxGeometry x="530" y="40" width="30" height="30" as="geometry" />
</mxCell>
<mxCell id="27" value="Write Once, Run Anywhere" style="text;html=1;strokeColor=none;fillColor=#1e3a5f;align=center;verticalAlign=middle;fontSize=14;fontColor=#ffffff;fontStyle=3;rounded=1;spacingLeft=10;spacingRight=10;" vertex="1" parent="1">
<mxGeometry x="330" y="560" width="240" height="35" as="geometry" />
</mxCell>
<mxCell id="28" value="JVM 层" style="text;html=1;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;fontSize=11;fontColor=#94a3b8;fontStyle=2;" vertex="1" parent="1">
<mxGeometry x="10" y="345" width="50" height="20" as="geometry" />
</mxCell>
<mxCell id="29" value="硬件层" style="text;html=1;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;fontSize=11;fontColor=#94a3b8;fontStyle=2;" vertex="1" parent="1">
<mxGeometry x="10" y="465" width="50" height="20" as="geometry" />
</mxCell>
</root>
</mxGraphModel>
</diagram>
</mxfile>
跨平台的本质
// 同一份代码
public class CrossPlatformDemo {
public static void main(String[] args) {
System.out.println("当前操作系统: " + System.getProperty("os.name"));
System.out.println("Java 版本: " + System.getProperty("java.version"));
System.out.println("文件分隔符: " + java.io.File.separator);
}
}
运行结果(不同平台):
Windows: Linux: macOS:
当前操作系统: Windows 10 当前操作系统: Linux 当前操作系统: Mac OS X
Java 版本: 17.0.2 Java 版本: 17.0.2 Java 版本: 17.0.2
文件分隔符: \ 文件分隔符: / 文件分隔符: /
⚠️ 现代视角:容器技术(Docker/K8s)成熟后,跨平台已不再是 Java 独有优势。Java 真正的核心竞争力是其庞大成熟的生态系统。
2.4 内置多线程支持
Java vs C++ 多线程对比
// ==================== Java 多线程(语言原生支持)====================
public class JavaThread extends Thread {
@Override
public void run() {
System.out.println("Java 线程运行中: " + Thread.currentThread().getName());
}
public static void main(String[] args) {
new JavaThread().start();
// 或使用 Lambda(Java 8+)
new Thread(() -> System.out.println("Lambda 线程")).start();
// 或使用线程池
ExecutorService executor = Executors.newFixedThreadPool(4);
executor.submit(() -> System.out.println("线程池任务"));
}
}
// ==================== C++ 多线程(C++11 前需要依赖系统 API)====================
// C++11 之前 - Windows 平台
#include <windows.h>
DWORD WINAPI ThreadFunc(LPVOID lpParam) {
printf("Windows 线程\n");
return 0;
}
int main() {
CreateThread(NULL, 0, ThreadFunc, NULL, 0, NULL);
}
// C++11 之后 - 标准库支持
#include <thread>
int main() {
std::thread t([]() {
std::cout << "C++11 标准线程" << std::endl;
});
t.join();
}
Java 并发包体系
<mxfile host="embed.diagrams.net" agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36" version="29.2.9">
<diagram id="java-concurrent-package" name="java.util.concurrent 并发包">
<mxGraphModel dx="1665" dy="798" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="900" pageHeight="680" math="0" shadow="0">
<root>
<mxCell id="0" />
<mxCell id="1" parent="0" />
<mxCell id="2" parent="1" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#1e3a5f;strokeColor=#1e3a5f;fontColor=#ffffff;fontStyle=1;fontSize=18;verticalAlign=middle;" value="java.util.concurrent 并发包" vertex="1">
<mxGeometry height="50" width="820" x="40" y="30" as="geometry" />
</mxCell>
<mxCell id="3" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#f8fafc;strokeColor=#cbd5e1;strokeWidth=2;" value="" vertex="1">
<mxGeometry height="560" width="820" x="40" y="80" as="geometry" />
</mxCell>
<mxCell id="4" parent="1" style="swimlane;fontStyle=1;align=center;verticalAlign=top;childLayout=stackLayout;horizontal=1;startSize=35;horizontalStack=0;resizeParent=1;resizeParentMax=0;resizeLast=0;collapsible=0;marginBottom=0;fillColor=#3b82f6;strokeColor=#2563eb;fontColor=#ffffff;fontSize=14;rounded=1;shadow=1;" value="线程池" vertex="1">
<mxGeometry height="140" width="170" x="70" y="110" as="geometry" />
</mxCell>
<mxCell id="5" parent="4" style="text;strokeColor=#bfdbfe;fillColor=#dbeafe;align=center;verticalAlign=middle;spacingLeft=4;spacingRight=4;overflow=hidden;rotatable=0;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;fontColor=#1e40af;fontSize=12;fontFamily=Consolas;" value="ThreadPoolExecutor" vertex="1">
<mxGeometry height="35" width="170" y="35" as="geometry" />
</mxCell>
<mxCell id="6" parent="4" style="text;strokeColor=#bfdbfe;fillColor=#eff6ff;align=center;verticalAlign=middle;spacingLeft=4;spacingRight=4;overflow=hidden;rotatable=0;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;fontColor=#1e40af;fontSize=12;fontFamily=Consolas;" value="ScheduledExecutor" vertex="1">
<mxGeometry height="35" width="170" y="70" as="geometry" />
</mxCell>
<mxCell id="7" parent="4" style="text;strokeColor=#bfdbfe;fillColor=#dbeafe;align=center;verticalAlign=middle;spacingLeft=4;spacingRight=4;overflow=hidden;rotatable=0;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;fontColor=#1e40af;fontSize=12;fontFamily=Consolas;" value="ForkJoinPool" vertex="1">
<mxGeometry height="35" width="170" y="105" as="geometry" />
</mxCell>
<mxCell id="8" parent="1" style="swimlane;fontStyle=1;align=center;verticalAlign=top;childLayout=stackLayout;horizontal=1;startSize=35;horizontalStack=0;resizeParent=1;resizeParentMax=0;resizeLast=0;collapsible=0;marginBottom=0;fillColor=#8b5cf6;strokeColor=#7c3aed;fontColor=#ffffff;fontSize=14;rounded=1;shadow=1;" value="锁机制" vertex="1">
<mxGeometry height="140" width="170" x="260" y="110" as="geometry" />
</mxCell>
<mxCell id="9" parent="8" style="text;strokeColor=#ddd6fe;fillColor=#ede9fe;align=center;verticalAlign=middle;spacingLeft=4;spacingRight=4;overflow=hidden;rotatable=0;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;fontColor=#5b21b6;fontSize=12;fontFamily=Consolas;" value="ReentrantLock" vertex="1">
<mxGeometry height="35" width="170" y="35" as="geometry" />
</mxCell>
<mxCell id="10" parent="8" style="text;strokeColor=#ddd6fe;fillColor=#f5f3ff;align=center;verticalAlign=middle;spacingLeft=4;spacingRight=4;overflow=hidden;rotatable=0;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;fontColor=#5b21b6;fontSize=12;fontFamily=Consolas;" value="ReadWriteLock" vertex="1">
<mxGeometry height="35" width="170" y="70" as="geometry" />
</mxCell>
<mxCell id="11" parent="8" style="text;strokeColor=#ddd6fe;fillColor=#ede9fe;align=center;verticalAlign=middle;spacingLeft=4;spacingRight=4;overflow=hidden;rotatable=0;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;fontColor=#5b21b6;fontSize=12;fontFamily=Consolas;" value="Condition" vertex="1">
<mxGeometry height="35" width="170" y="105" as="geometry" />
</mxCell>
<mxCell id="12" parent="1" style="swimlane;fontStyle=1;align=center;verticalAlign=top;childLayout=stackLayout;horizontal=1;startSize=35;horizontalStack=0;resizeParent=1;resizeParentMax=0;resizeLast=0;collapsible=0;marginBottom=0;fillColor=#22c55e;strokeColor=#16a34a;fontColor=#ffffff;fontSize=14;rounded=1;shadow=1;" value="并发集合" vertex="1">
<mxGeometry height="140" width="180" x="450" y="110" as="geometry" />
</mxCell>
<mxCell id="13" parent="12" style="text;strokeColor=#bbf7d0;fillColor=#dcfce7;align=center;verticalAlign=middle;spacingLeft=4;spacingRight=4;overflow=hidden;rotatable=0;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;fontColor=#166534;fontSize=12;fontFamily=Consolas;" value="ConcurrentHashMap" vertex="1">
<mxGeometry height="35" width="180" y="35" as="geometry" />
</mxCell>
<mxCell id="14" parent="12" style="text;strokeColor=#bbf7d0;fillColor=#f0fdf4;align=center;verticalAlign=middle;spacingLeft=4;spacingRight=4;overflow=hidden;rotatable=0;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;fontColor=#166534;fontSize=12;fontFamily=Consolas;" value="CopyOnWriteArrayList" vertex="1">
<mxGeometry height="35" width="180" y="70" as="geometry" />
</mxCell>
<mxCell id="15" parent="12" style="text;strokeColor=#bbf7d0;fillColor=#dcfce7;align=center;verticalAlign=middle;spacingLeft=4;spacingRight=4;overflow=hidden;rotatable=0;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;fontColor=#166534;fontSize=12;fontFamily=Consolas;" value="BlockingQueue" vertex="1">
<mxGeometry height="35" width="180" y="105" as="geometry" />
</mxCell>
<mxCell id="16" parent="1" style="swimlane;fontStyle=1;align=center;verticalAlign=top;childLayout=stackLayout;horizontal=1;startSize=35;horizontalStack=0;resizeParent=1;resizeParentMax=0;resizeLast=0;collapsible=0;marginBottom=0;fillColor=#f59e0b;strokeColor=#d97706;fontColor=#ffffff;fontSize=14;rounded=1;shadow=1;" value="原子类" vertex="1">
<mxGeometry height="140" width="170" x="650" y="110" as="geometry" />
</mxCell>
<mxCell id="17" parent="16" style="text;strokeColor=#fde68a;fillColor=#fef3c7;align=center;verticalAlign=middle;spacingLeft=4;spacingRight=4;overflow=hidden;rotatable=0;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;fontColor=#92400e;fontSize=12;fontFamily=Consolas;" value="AtomicInteger" vertex="1">
<mxGeometry height="35" width="170" y="35" as="geometry" />
</mxCell>
<mxCell id="18" parent="16" style="text;strokeColor=#fde68a;fillColor=#fffbeb;align=center;verticalAlign=middle;spacingLeft=4;spacingRight=4;overflow=hidden;rotatable=0;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;fontColor=#92400e;fontSize=12;fontFamily=Consolas;" value="AtomicLong" vertex="1">
<mxGeometry height="35" width="170" y="70" as="geometry" />
</mxCell>
<mxCell id="19" parent="16" style="text;strokeColor=#fde68a;fillColor=#fef3c7;align=center;verticalAlign=middle;spacingLeft=4;spacingRight=4;overflow=hidden;rotatable=0;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;fontColor=#92400e;fontSize=12;fontFamily=Consolas;" value="AtomicReference" vertex="1">
<mxGeometry height="35" width="170" y="105" as="geometry" />
</mxCell>
<mxCell id="20" parent="1" style="swimlane;fontStyle=1;align=center;verticalAlign=top;childLayout=stackLayout;horizontal=1;startSize=35;horizontalStack=0;resizeParent=1;resizeParentMax=0;resizeLast=0;collapsible=0;marginBottom=0;fillColor=#ec4899;strokeColor=#db2777;fontColor=#ffffff;fontSize=14;rounded=1;shadow=1;" value="同步工具" vertex="1">
<mxGeometry height="140" width="170" x="170" y="280" as="geometry" />
</mxCell>
<mxCell id="21" parent="20" style="text;strokeColor=#fbcfe8;fillColor=#fce7f3;align=center;verticalAlign=middle;spacingLeft=4;spacingRight=4;overflow=hidden;rotatable=0;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;fontColor=#9d174d;fontSize=12;fontFamily=Consolas;" value="CountDownLatch" vertex="1">
<mxGeometry height="35" width="170" y="35" as="geometry" />
</mxCell>
<mxCell id="22" parent="20" style="text;strokeColor=#fbcfe8;fillColor=#fdf2f8;align=center;verticalAlign=middle;spacingLeft=4;spacingRight=4;overflow=hidden;rotatable=0;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;fontColor=#9d174d;fontSize=12;fontFamily=Consolas;" value="CyclicBarrier" vertex="1">
<mxGeometry height="35" width="170" y="70" as="geometry" />
</mxCell>
<mxCell id="23" parent="20" style="text;strokeColor=#fbcfe8;fillColor=#fce7f3;align=center;verticalAlign=middle;spacingLeft=4;spacingRight=4;overflow=hidden;rotatable=0;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;fontColor=#9d174d;fontSize=12;fontFamily=Consolas;" value="Semaphore" vertex="1">
<mxGeometry height="35" width="170" y="105" as="geometry" />
</mxCell>
<mxCell id="24" parent="1" style="swimlane;fontStyle=1;align=center;verticalAlign=top;childLayout=stackLayout;horizontal=1;startSize=35;horizontalStack=0;resizeParent=1;resizeParentMax=0;resizeLast=0;collapsible=0;marginBottom=0;fillColor=#06b6d4;strokeColor=#0891b2;fontColor=#ffffff;fontSize=14;rounded=1;shadow=1;" value="Future" vertex="1">
<mxGeometry height="140" width="170" x="360" y="280" as="geometry" />
</mxCell>
<mxCell id="25" parent="24" style="text;strokeColor=#a5f3fc;fillColor=#cffafe;align=center;verticalAlign=middle;spacingLeft=4;spacingRight=4;overflow=hidden;rotatable=0;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;fontColor=#155e75;fontSize=12;fontFamily=Consolas;" value="Future<V>" vertex="1">
<mxGeometry height="35" width="170" y="35" as="geometry" />
</mxCell>
<mxCell id="26" parent="24" style="text;strokeColor=#a5f3fc;fillColor=#ecfeff;align=center;verticalAlign=middle;spacingLeft=4;spacingRight=4;overflow=hidden;rotatable=0;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;fontColor=#155e75;fontSize=12;fontFamily=Consolas;" value="Callable<V>" vertex="1">
<mxGeometry height="35" width="170" y="70" as="geometry" />
</mxCell>
<mxCell id="27" parent="24" style="text;strokeColor=#a5f3fc;fillColor=#cffafe;align=center;verticalAlign=middle;spacingLeft=4;spacingRight=4;overflow=hidden;rotatable=0;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;fontColor=#155e75;fontSize=12;fontFamily=Consolas;" value="FutureTask<V>" vertex="1">
<mxGeometry height="35" width="170" y="105" as="geometry" />
</mxCell>
<mxCell id="28" parent="1" style="swimlane;fontStyle=1;align=center;verticalAlign=top;childLayout=stackLayout;horizontal=1;startSize=35;horizontalStack=0;resizeParent=1;resizeParentMax=0;resizeLast=0;collapsible=0;marginBottom=0;fillColor=#ef4444;strokeColor=#dc2626;fontColor=#ffffff;fontSize=14;rounded=1;shadow=1;" value="CompletableFuture" vertex="1">
<mxGeometry height="140" width="180" x="550" y="280" as="geometry" />
</mxCell>
<mxCell id="29" parent="28" style="text;strokeColor=#fecaca;fillColor=#fee2e2;align=center;verticalAlign=middle;spacingLeft=4;spacingRight=4;overflow=hidden;rotatable=0;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;fontColor=#991b1b;fontSize=12;" value="异步编程" vertex="1">
<mxGeometry height="35" width="180" y="35" as="geometry" />
</mxCell>
<mxCell id="30" parent="28" style="text;strokeColor=#fecaca;fillColor=#fef2f2;align=center;verticalAlign=middle;spacingLeft=4;spacingRight=4;overflow=hidden;rotatable=0;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;fontColor=#991b1b;fontSize=12;" value="链式调用" vertex="1">
<mxGeometry height="35" width="180" y="70" as="geometry" />
</mxCell>
<mxCell id="31" parent="28" style="text;strokeColor=#fecaca;fillColor=#fee2e2;align=center;verticalAlign=middle;spacingLeft=4;spacingRight=4;overflow=hidden;rotatable=0;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;fontColor=#991b1b;fontSize=12;" value="组合操作" vertex="1">
<mxGeometry height="35" width="180" y="105" as="geometry" />
</mxCell>
<mxCell id="32" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;fontSize=20;" value="🧵" vertex="1">
<mxGeometry height="30" width="30" x="200" y="110" as="geometry" />
</mxCell>
<mxCell id="33" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;fontSize=20;" value="🔒" vertex="1">
<mxGeometry height="30" width="30" x="390" y="110" as="geometry" />
</mxCell>
<mxCell id="34" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;fontSize=20;" value="📦" vertex="1">
<mxGeometry height="30" width="30" x="590" y="110" as="geometry" />
</mxCell>
<mxCell id="35" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;fontSize=20;" value="⚛️" vertex="1">
<mxGeometry height="30" width="30" x="780" y="110" as="geometry" />
</mxCell>
<mxCell id="36" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;fontSize=20;" value="🔄" vertex="1">
<mxGeometry height="30" width="30" x="300" y="280" as="geometry" />
</mxCell>
<mxCell id="37" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;fontSize=20;" value="⏳" vertex="1">
<mxGeometry height="30" width="30" x="490" y="280" as="geometry" />
</mxCell>
<mxCell id="38" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;fontSize=20;" value="🚀" vertex="1">
<mxGeometry height="30" width="30" x="690" y="280" as="geometry" />
</mxCell>
<mxCell id="39" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;fontSize=14;fontStyle=1;fontColor=#475569;" value="核心特性" vertex="1">
<mxGeometry height="30" width="100" x="160" y="450" as="geometry" />
</mxCell>
<mxCell id="40" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dbeafe;strokeColor=#3b82f6;fontColor=#1e40af;fontSize=12;fontStyle=1;" value="线程安全" vertex="1">
<mxGeometry height="40" width="100" x="160" y="490" as="geometry" />
</mxCell>
<mxCell id="41" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dcfce7;strokeColor=#22c55e;fontColor=#166534;fontSize=12;fontStyle=1;" value="高性能" vertex="1">
<mxGeometry height="40" width="100" x="280" y="490" as="geometry" />
</mxCell>
<mxCell id="42" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fef3c7;strokeColor=#f59e0b;fontColor=#92400e;fontSize=12;fontStyle=1;" value="无锁算法" vertex="1">
<mxGeometry height="40" width="100" x="400" y="490" as="geometry" />
</mxCell>
<mxCell id="43" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#ede9fe;strokeColor=#8b5cf6;fontColor=#5b21b6;fontSize=12;fontStyle=1;" value="可扩展性" vertex="1">
<mxGeometry height="40" width="100" x="520" y="490" as="geometry" />
</mxCell>
<mxCell id="44" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fce7f3;strokeColor=#ec4899;fontColor=#9d174d;fontSize=12;fontStyle=1;" value="异步支持" vertex="1">
<mxGeometry height="40" width="100" x="640" y="490" as="geometry" />
</mxCell>
<mxCell id="45" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#1e3a5f;strokeColor=#1e3a5f;fontColor=#ffffff;fontSize=13;fontStyle=1;" value="💡 JDK 5+ 引入,持续增强至今" vertex="1">
<mxGeometry height="40" width="580" x="160" y="560" as="geometry" />
</mxCell>
</root>
</mxGraphModel>
</diagram>
</mxfile>
2.5 自动内存管理(GC)
手动 vs 自动内存管理
// ==================== C++ 手动内存管理 ====================
int main() {
int* arr = new int[100]; // 申请内存
// 使用内存...
delete[] arr; // 必须手动释放!
arr = nullptr; // 避免悬空指针
// 忘记 delete → 内存泄漏
// 重复 delete → 程序崩溃
// 使用已释放内存 → 未定义行为
}
// ==================== Java 自动内存管理 ====================
public class MemoryDemo {
public static void main(String[] args) {
int[] arr = new int[100]; // 在堆上分配
// 使用内存...
arr = null; // 解除引用(可选)
// JVM 的 GC 会自动回收不再使用的对象
// 程序员无需关心何时释放
}
}
GC 工作原理简图
<mxfile host="embed.diagrams.net" agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36" version="29.2.9">
<diagram id="jvm-heap-memory" name="JVM 堆内存结构">
<mxGraphModel dx="1388" dy="665" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="900" pageHeight="700" math="0" shadow="0">
<root>
<mxCell id="0" />
<mxCell id="1" parent="0" />
<mxCell id="2" parent="1" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#1e3a5f;strokeColor=#1e3a5f;fontColor=#ffffff;fontStyle=1;fontSize=18;verticalAlign=middle;" value="JVM 堆内存结构" vertex="1">
<mxGeometry height="50" width="820" x="40" y="30" as="geometry" />
</mxCell>
<mxCell id="3" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#f8fafc;strokeColor=#cbd5e1;strokeWidth=2;" value="" vertex="1">
<mxGeometry height="580" width="820" x="40" y="80" as="geometry" />
</mxCell>
<mxCell id="4" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#22c55e;strokeColor=#16a34a;fontColor=#ffffff;fontStyle=1;fontSize=14;verticalAlign=top;spacingTop=8;" value="年轻代 (Young Generation)" vertex="1">
<mxGeometry height="280" width="420" x="60" y="110" as="geometry" />
</mxCell>
<mxCell id="5" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#86efac;strokeColor=#22c55e;fontColor=#166534;fontStyle=1;fontSize=14;verticalAlign=top;spacingTop=8;" value="Eden 区" vertex="1">
<mxGeometry height="180" width="160" x="80" y="150" as="geometry" />
</mxCell>
<mxCell id="6" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;fontSize=12;fontColor=#166534;" value="🆕 新对象分配区域

大部分对象在此创建
空间最大" vertex="1">
<mxGeometry height="120" width="150" x="85" y="190" as="geometry" />
</mxCell>
<mxCell id="7" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fef3c7;strokeColor=#f59e0b;fontColor=#92400e;fontStyle=1;fontSize=13;verticalAlign=top;spacingTop=8;" value="S0 (From)" vertex="1">
<mxGeometry height="180" width="100" x="260" y="150" as="geometry" />
</mxCell>
<mxCell id="8" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;fontSize=11;fontColor=#92400e;" value="幸存区

存放GC后
存活对象" vertex="1">
<mxGeometry height="120" width="90" x="265" y="190" as="geometry" />
</mxCell>
<mxCell id="9" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fef3c7;strokeColor=#f59e0b;fontColor=#92400e;fontStyle=1;fontSize=13;verticalAlign=top;spacingTop=8;" value="S1 (To)" vertex="1">
<mxGeometry height="180" width="100" x="370" y="150" as="geometry" />
</mxCell>
<mxCell id="10" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;fontSize=11;fontColor=#92400e;" value="幸存区

与S0交替
使用" vertex="1">
<mxGeometry height="120" width="90" x="375" y="190" as="geometry" />
</mxCell>
<mxCell id="11" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dcfce7;strokeColor=#22c55e;fontColor=#166534;fontSize=12;fontStyle=1;" value="⚡ Minor GC - 频繁触发、速度快" vertex="1">
<mxGeometry height="35" width="390" x="80" y="345" as="geometry" />
</mxCell>
<mxCell id="12" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#3b82f6;strokeColor=#2563eb;fontColor=#ffffff;fontStyle=1;fontSize=14;verticalAlign=top;spacingTop=8;" value="老年代 (Old Generation)" vertex="1">
<mxGeometry height="280" width="340" x="500" y="110" as="geometry" />
</mxCell>
<mxCell id="13" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dbeafe;strokeColor=#3b82f6;" value="" vertex="1">
<mxGeometry height="180" width="300" x="520" y="150" as="geometry" />
</mxCell>
<mxCell id="14" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;fontSize=12;fontColor=#1e40af;" value="🏛️ 长期存活对象存储区

• 经过多次 Minor GC 存活的对象
• 大对象直接分配
• 空间较大,GC 频率低" vertex="1">
<mxGeometry height="140" width="280" x="530" y="170" as="geometry" />
</mxCell>
<mxCell id="15" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#bfdbfe;strokeColor=#3b82f6;fontColor=#1e40af;fontSize=12;fontStyle=1;" value="🐢 Major GC / Full GC - 较慢、STW 时间长" vertex="1">
<mxGeometry height="35" width="300" x="520" y="345" as="geometry" />
</mxCell>
<mxCell id="16" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;fontSize=14;fontStyle=1;fontColor=#475569;" value="对象晋升流程" vertex="1">
<mxGeometry height="30" width="120" x="60" y="410" as="geometry" />
</mxCell>
<mxCell id="17" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#86efac;strokeColor=#22c55e;fontColor=#166534;fontSize=12;fontStyle=1;" value="新对象创建" vertex="1">
<mxGeometry height="45" width="100" x="60" y="450" as="geometry" />
</mxCell>
<mxCell id="18" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#86efac;strokeColor=#22c55e;fontColor=#166534;fontSize=12;fontStyle=1;" value="Eden 区" vertex="1">
<mxGeometry height="45" width="100" x="200" y="450" as="geometry" />
</mxCell>
<mxCell id="19" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fef3c7;strokeColor=#f59e0b;fontColor=#92400e;fontSize=12;fontStyle=1;" value="Survivor 区
(S0 ↔ S1)" vertex="1">
<mxGeometry height="45" width="120" x="380" y="450" as="geometry" />
</mxCell>
<mxCell id="20" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dbeafe;strokeColor=#3b82f6;fontColor=#1e40af;fontSize=12;fontStyle=1;" value="Old 区" vertex="1">
<mxGeometry height="45" width="100" x="580" y="450" as="geometry" />
</mxCell>
<mxCell id="21" edge="1" parent="1" source="17" style="edgeStyle=orthogonalEdgeStyle;strokeColor=#22c55e;strokeWidth=2;endArrow=classic;" target="18">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="22" edge="1" parent="1" source="18" style="edgeStyle=orthogonalEdgeStyle;strokeColor=#f59e0b;strokeWidth=2;endArrow=classic;" target="19">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="23" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;fontSize=10;fontColor=#f59e0b;" value="Minor GC
存活" vertex="1">
<mxGeometry height="30" width="70" x="300" y="445" as="geometry" />
</mxCell>
<mxCell id="24" edge="1" parent="1" source="19" style="edgeStyle=orthogonalEdgeStyle;strokeColor=#3b82f6;strokeWidth=2;endArrow=classic;" target="20">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="25" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;fontSize=10;fontColor=#3b82f6;" value="年龄达到
阈值(15)" vertex="1">
<mxGeometry height="30" width="70" x="500" y="445" as="geometry" />
</mxCell>
<mxCell id="26" parent="1" style="ellipse;whiteSpace=wrap;html=1;fillColor=#fee2e2;strokeColor=#ef4444;fontColor=#991b1b;fontSize=11;fontStyle=1;" value="GC 回收" vertex="1">
<mxGeometry height="45" width="80" x="720" y="450" as="geometry" />
</mxCell>
<mxCell id="27" edge="1" parent="1" source="18" style="edgeStyle=orthogonalEdgeStyle;strokeColor=#ef4444;strokeWidth=2;endArrow=classic;dashed=1;" target="26">
<mxGeometry relative="1" as="geometry">
<Array as="points">
<mxPoint x="250" y="520" />
<mxPoint x="760" y="520" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="28" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;fontSize=10;fontColor=#ef4444;" value="未存活对象" vertex="1">
<mxGeometry height="20" width="70" x="460" y="505" as="geometry" />
</mxCell>
<mxCell id="29" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;fontSize=14;fontStyle=1;fontColor=#475569;" value="内存分配比例参考" vertex="1">
<mxGeometry height="30" width="150" x="60" y="550" as="geometry" />
</mxCell>
<mxCell id="30" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#e2e8f0;strokeColor=#94a3b8;" value="" vertex="1">
<mxGeometry height="50" width="780" x="60" y="585" as="geometry" />
</mxCell>
<mxCell id="31" parent="1" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#86efac;strokeColor=#22c55e;fontColor=#166534;fontSize=11;fontStyle=1;" value="Eden (8)" vertex="1">
<mxGeometry height="30" width="200" x="70" y="595" as="geometry" />
</mxCell>
<mxCell id="32" parent="1" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#fef3c7;strokeColor=#f59e0b;fontColor=#92400e;fontSize=11;fontStyle=1;" value="S0 (1)" vertex="1">
<mxGeometry height="30" width="50" x="270" y="595" as="geometry" />
</mxCell>
<mxCell id="33" parent="1" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#fef3c7;strokeColor=#f59e0b;fontColor=#92400e;fontSize=11;fontStyle=1;" value="S1 (1)" vertex="1">
<mxGeometry height="30" width="50" x="320" y="595" as="geometry" />
</mxCell>
<mxCell id="34" parent="1" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#dbeafe;strokeColor=#3b82f6;fontColor=#1e40af;fontSize=11;fontStyle=1;" value="Old Generation (2/3 of Heap)" vertex="1">
<mxGeometry height="30" width="450" x="380" y="595" as="geometry" />
</mxCell>
<mxCell id="35" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;fontSize=10;fontColor=#166534;fontStyle=2;" value="Young (1/3)" vertex="1">
<mxGeometry height="20" width="80" x="150" y="625" as="geometry" />
</mxCell>
<mxCell id="36" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;fontSize=10;fontColor=#1e40af;fontStyle=2;" value="Old (2/3)" vertex="1">
<mxGeometry height="20" width="80" x="560" y="625" as="geometry" />
</mxCell>
<mxCell id="37" parent="1" style="text;html=1;strokeColor=none;fillColor=#1e3a5f;align=center;verticalAlign=middle;fontSize=11;fontColor=#ffffff;rounded=1;fontFamily=Consolas;" value="💡 -XX:NewRatio=2 (Old:Young=2:1) | -XX:SurvivorRatio=8 (Eden:S0:S1=8:1:1)" vertex="1">
<mxGeometry height="25" width="500" x="200" y="664" as="geometry" />
</mxCell>
</root>
</mxGraphModel>
</diagram>
</mxfile>
2.6 安全机制
<mxfile host="embed.diagrams.net" agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36" version="29.2.9">
<diagram id="java-security-architecture" name="Java 安全体系架构">
<mxGraphModel dx="1665" dy="798" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="900" pageHeight="750" math="0" shadow="0">
<root>
<mxCell id="0" />
<mxCell id="1" parent="0" />
<mxCell id="2" parent="1" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#1e3a5f;strokeColor=#1e3a5f;fontColor=#ffffff;fontStyle=1;fontSize=18;verticalAlign=middle;" value="Java 安全体系架构" vertex="1">
<mxGeometry height="50" width="820" x="40" y="30" as="geometry" />
</mxCell>
<mxCell id="3" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#f8fafc;strokeColor=#cbd5e1;strokeWidth=2;" value="" vertex="1">
<mxGeometry height="750" width="820" x="40" y="80" as="geometry" />
</mxCell>
<mxCell id="4" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#22c55e;strokeColor=#16a34a;fontColor=#ffffff;fontStyle=1;fontSize=15;verticalAlign=middle;" value="🛡️ 第一层:源代码层面安全" vertex="1">
<mxGeometry height="45" width="280" x="70" y="120" as="geometry" />
</mxCell>
<mxCell id="5" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dcfce7;strokeColor=#22c55e;strokeWidth=2;" value="" vertex="1">
<mxGeometry height="155" width="280" x="70" y="175" as="geometry" />
</mxCell>
<mxCell id="6" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#86efac;strokeColor=#22c55e;fontColor=#166534;fontSize=12;fontStyle=1;" value="强类型检查" vertex="1">
<mxGeometry height="35" width="110" x="85" y="190" as="geometry" />
</mxCell>
<mxCell id="7" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#86efac;strokeColor=#22c55e;fontColor=#166534;fontSize=12;fontStyle=1;" value="访问控制修饰符" vertex="1">
<mxGeometry height="35" width="110" x="85" y="235" as="geometry" />
</mxCell>
<mxCell id="8" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#86efac;strokeColor=#22c55e;fontColor=#166534;fontSize=12;fontStyle=1;" value="数组边界检查" vertex="1">
<mxGeometry height="35" width="110" x="85" y="280" as="geometry" />
</mxCell>
<mxCell id="9" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;fontSize=11;fontColor=#166534;" value="编译期发现类型错误" vertex="1">
<mxGeometry height="35" width="140" x="205" y="190" as="geometry" />
</mxCell>
<mxCell id="10" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;fontSize=11;fontColor=#166534;fontFamily=Consolas;" value="public/private/protected" vertex="1">
<mxGeometry height="35" width="140" x="205" y="235" as="geometry" />
</mxCell>
<mxCell id="11" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;fontSize=11;fontColor=#166534;" value="运行时自动检查" vertex="1">
<mxGeometry height="35" width="140" x="205" y="280" as="geometry" />
</mxCell>
<mxCell id="12" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#3b82f6;strokeColor=#2563eb;fontColor=#ffffff;fontStyle=1;fontSize=15;verticalAlign=middle;" value="🔍 第二层:字节码验证" vertex="1">
<mxGeometry height="45" width="280" x="70" y="350" as="geometry" />
</mxCell>
<mxCell id="13" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dbeafe;strokeColor=#3b82f6;strokeWidth=2;" value="" vertex="1">
<mxGeometry height="155" width="280" x="70" y="405" as="geometry" />
</mxCell>
<mxCell id="14" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#93c5fd;strokeColor=#3b82f6;fontColor=#1e40af;fontSize=12;fontStyle=1;" value="格式检查" vertex="1">
<mxGeometry height="35" width="110" x="85" y="420" as="geometry" />
</mxCell>
<mxCell id="15" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#93c5fd;strokeColor=#3b82f6;fontColor=#1e40af;fontSize=12;fontStyle=1;" value="语义分析" vertex="1">
<mxGeometry height="35" width="110" x="85" y="465" as="geometry" />
</mxCell>
<mxCell id="16" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#93c5fd;strokeColor=#3b82f6;fontColor=#1e40af;fontSize=12;fontStyle=1;" value="字节码验证" vertex="1">
<mxGeometry height="35" width="110" x="85" y="510" as="geometry" />
</mxCell>
<mxCell id="17" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;fontSize=11;fontColor=#1e40af;" value="魔数、版本号验证" vertex="1">
<mxGeometry height="35" width="140" x="205" y="420" as="geometry" />
</mxCell>
<mxCell id="18" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;fontSize=11;fontColor=#1e40af;" value="类型安全验证" vertex="1">
<mxGeometry height="35" width="140" x="205" y="465" as="geometry" />
</mxCell>
<mxCell id="19" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;fontSize=11;fontColor=#1e40af;" value="栈操作合法性" vertex="1">
<mxGeometry height="35" width="140" x="205" y="510" as="geometry" />
</mxCell>
<mxCell id="20" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#8b5cf6;strokeColor=#7c3aed;fontColor=#ffffff;fontStyle=1;fontSize=15;verticalAlign=middle;" value="🔒 第三层:运行时保护" vertex="1">
<mxGeometry height="45" width="280" x="70" y="580" as="geometry" />
</mxCell>
<mxCell id="21" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#ede9fe;strokeColor=#8b5cf6;strokeWidth=2;" value="" vertex="1">
<mxGeometry height="155" width="280" x="70" y="635" as="geometry" />
</mxCell>
<mxCell id="22" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#c4b5fd;strokeColor=#8b5cf6;fontColor=#5b21b6;fontSize=12;fontStyle=1;" value="类加载器隔离" vertex="1">
<mxGeometry height="35" width="110" x="85" y="650" as="geometry" />
</mxCell>
<mxCell id="23" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#c4b5fd;strokeColor=#8b5cf6;fontColor=#5b21b6;fontSize=12;fontStyle=1;" value="安全管理器" vertex="1">
<mxGeometry height="35" width="110" x="85" y="695" as="geometry" />
</mxCell>
<mxCell id="24" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#c4b5fd;strokeColor=#8b5cf6;fontColor=#5b21b6;fontSize=12;fontStyle=1;" value="沙箱机制" vertex="1">
<mxGeometry height="35" width="110" x="85" y="740" as="geometry" />
</mxCell>
<mxCell id="25" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;fontSize=11;fontColor=#5b21b6;" value="不同来源的类相互隔离" vertex="1">
<mxGeometry height="35" width="140" x="205" y="650" as="geometry" />
</mxCell>
<mxCell id="26" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;fontSize=11;fontColor=#5b21b6;" value="控制代码权限 ⚠️已弃用" vertex="1">
<mxGeometry height="35" width="140" x="205" y="695" as="geometry" />
</mxCell>
<mxCell id="27" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;fontSize=11;fontColor=#5b21b6;" value="限制不可信代码" vertex="1">
<mxGeometry height="35" width="140" x="205" y="740" as="geometry" />
</mxCell>
<mxCell id="28" edge="1" parent="1" style="edgeStyle=orthogonalEdgeStyle;strokeColor=#16a34a;strokeWidth=3;endArrow=classic;endSize=10;">
<mxGeometry relative="1" as="geometry">
<mxPoint x="209.5" y="330" as="sourcePoint" />
<mxPoint x="209.5" y="355" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="29" edge="1" parent="1" style="edgeStyle=orthogonalEdgeStyle;strokeColor=#2563eb;strokeWidth=3;endArrow=classic;endSize=10;">
<mxGeometry relative="1" as="geometry">
<mxPoint x="209.5" y="555" as="sourcePoint" />
<mxPoint x="209.5" y="580" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="30" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;fontSize=14;fontStyle=1;fontColor=#475569;" value="安全执行流程" vertex="1">
<mxGeometry height="30" width="120" x="400" y="110" as="geometry" />
</mxCell>
<mxCell id="31" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fef3c7;strokeColor=#f59e0b;fontColor=#92400e;fontSize=12;fontStyle=1;" value=".java 源文件" vertex="1">
<mxGeometry height="40" width="120" x="400" y="150" as="geometry" />
</mxCell>
<mxCell id="32" parent="1" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#22c55e;strokeColor=#16a34a;fontColor=#ffffff;fontSize=12;fontStyle=1;" value="javac 编译器" vertex="1">
<mxGeometry height="40" width="120" x="400" y="220" as="geometry" />
</mxCell>
<mxCell id="33" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fef3c7;strokeColor=#f59e0b;fontColor=#92400e;fontSize=12;fontStyle=1;" value=".class 字节码" vertex="1">
<mxGeometry height="40" width="120" x="400" y="290" as="geometry" />
</mxCell>
<mxCell id="34" parent="1" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#3b82f6;strokeColor=#2563eb;fontColor=#ffffff;fontSize=12;fontStyle=1;" value="字节码验证器" vertex="1">
<mxGeometry height="40" width="120" x="400" y="360" as="geometry" />
</mxCell>
<mxCell id="35" parent="1" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#8b5cf6;strokeColor=#7c3aed;fontColor=#ffffff;fontSize=12;fontStyle=1;" value="类加载器" vertex="1">
<mxGeometry height="40" width="120" x="400" y="430" as="geometry" />
</mxCell>
<mxCell id="36" parent="1" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#8b5cf6;strokeColor=#7c3aed;fontColor=#ffffff;fontSize=12;fontStyle=1;" value="JVM 运行时" vertex="1">
<mxGeometry height="40" width="120" x="400" y="500" as="geometry" />
</mxCell>
<mxCell id="37" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dcfce7;strokeColor=#22c55e;fontColor=#166534;fontSize=12;fontStyle=1;" value="安全执行 ✓" vertex="1">
<mxGeometry height="40" width="120" x="400" y="570" as="geometry" />
</mxCell>
<mxCell id="38" edge="1" parent="1" source="31" style="edgeStyle=orthogonalEdgeStyle;strokeColor=#64748b;strokeWidth=2;endArrow=classic;" target="32">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="39" edge="1" parent="1" source="32" style="edgeStyle=orthogonalEdgeStyle;strokeColor=#64748b;strokeWidth=2;endArrow=classic;" target="33">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="40" edge="1" parent="1" source="33" style="edgeStyle=orthogonalEdgeStyle;strokeColor=#64748b;strokeWidth=2;endArrow=classic;" target="34">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="41" edge="1" parent="1" source="34" style="edgeStyle=orthogonalEdgeStyle;strokeColor=#64748b;strokeWidth=2;endArrow=classic;" target="35">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="42" edge="1" parent="1" source="35" style="edgeStyle=orthogonalEdgeStyle;strokeColor=#64748b;strokeWidth=2;endArrow=classic;" target="36">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="43" edge="1" parent="1" source="36" style="edgeStyle=orthogonalEdgeStyle;strokeColor=#64748b;strokeWidth=2;endArrow=classic;" target="37">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="44" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fee2e2;strokeColor=#ef4444;fontColor=#991b1b;fontSize=11;fontStyle=1;" value="拒绝 ✗" vertex="1">
<mxGeometry height="30" width="70" x="550" y="220" as="geometry" />
</mxCell>
<mxCell id="45" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fee2e2;strokeColor=#ef4444;fontColor=#991b1b;fontSize=11;fontStyle=1;" value="拒绝 ✗" vertex="1">
<mxGeometry height="30" width="70" x="550" y="365" as="geometry" />
</mxCell>
<mxCell id="46" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fee2e2;strokeColor=#ef4444;fontColor=#991b1b;fontSize=11;fontStyle=1;" value="拒绝 ✗" vertex="1">
<mxGeometry height="30" width="70" x="550" y="505" as="geometry" />
</mxCell>
<mxCell id="47" edge="1" parent="1" source="32" style="edgeStyle=orthogonalEdgeStyle;strokeColor=#ef4444;strokeWidth=1;endArrow=classic;dashed=1;" target="44">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="48" edge="1" parent="1" source="34" style="edgeStyle=orthogonalEdgeStyle;strokeColor=#ef4444;strokeWidth=1;endArrow=classic;dashed=1;" target="45">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="49" edge="1" parent="1" source="36" style="edgeStyle=orthogonalEdgeStyle;strokeColor=#ef4444;strokeWidth=1;endArrow=classic;dashed=1;" target="46">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="50" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;fontSize=14;fontStyle=1;fontColor=#475569;" value="核心安全机制" vertex="1">
<mxGeometry height="30" width="120" x="660" y="110" as="geometry" />
</mxCell>
<mxCell id="51" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#f1f5f9;strokeColor=#94a3b8;" value="" vertex="1">
<mxGeometry height="310" width="180" x="660" y="150" as="geometry" />
</mxCell>
<mxCell id="52" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dcfce7;strokeColor=#22c55e;fontColor=#166534;fontSize=12;fontStyle=1;" value="类型安全" vertex="1">
<mxGeometry height="35" width="140" x="680" y="170" as="geometry" />
</mxCell>
<mxCell id="53" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dbeafe;strokeColor=#3b82f6;fontColor=#1e40af;fontSize=12;fontStyle=1;" value="内存安全" vertex="1">
<mxGeometry height="35" width="140" x="680" y="215" as="geometry" />
</mxCell>
<mxCell id="54" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#ede9fe;strokeColor=#8b5cf6;fontColor=#5b21b6;fontSize=12;fontStyle=1;" value="访问控制" vertex="1">
<mxGeometry height="35" width="140" x="680" y="260" as="geometry" />
</mxCell>
<mxCell id="55" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fce7f3;strokeColor=#ec4899;fontColor=#9d174d;fontSize=12;fontStyle=1;" value="代码隔离" vertex="1">
<mxGeometry height="35" width="140" x="680" y="305" as="geometry" />
</mxCell>
<mxCell id="56" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fef3c7;strokeColor=#f59e0b;fontColor=#92400e;fontSize=12;fontStyle=1;" value="异常处理" vertex="1">
<mxGeometry height="35" width="140" x="680" y="350" as="geometry" />
</mxCell>
<mxCell id="57" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#cffafe;strokeColor=#06b6d4;fontColor=#155e75;fontSize=12;fontStyle=1;" value="加密支持" vertex="1">
<mxGeometry height="35" width="140" x="680" y="395" as="geometry" />
</mxCell>
<mxCell id="58" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#1e3a5f;strokeColor=#1e3a5f;fontColor=#ffffff;fontSize=12;fontStyle=1;" value="💡 Java 通过多层防护机制,从编译期到运行时全方位保障代码安全" vertex="1">
<mxGeometry height="60" width="180" x="660" y="480" as="geometry" />
</mxCell>
</root>
</mxGraphModel>
</diagram>
</mxfile>
// 类型安全示例
public class TypeSafetyDemo {
public static void main(String[] args) {
Object obj = "Hello";
// 编译期检查:必须显式转型
// int num = obj; // 编译错误!
// 运行时检查:类型转换安全
if (obj instanceof String str) { // Java 16+ 模式匹配
System.out.println(str.length());
}
// 数组边界检查
int[] arr = {1, 2, 3};
// arr[10] = 5; // 运行时抛出 ArrayIndexOutOfBoundsException
}
}
2.7 高性能优化(JIT 编译器)
<mxfile host="embed.diagrams.net" agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36" version="29.2.9">
<diagram id="jit-compilation-process" name="JIT 编译优化过程">
<mxGraphModel dx="1388" dy="665" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="900" pageHeight="700" math="0" shadow="0">
<root>
<mxCell id="0" />
<mxCell id="1" parent="0" />
<mxCell id="2" parent="1" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#1e3a5f;strokeColor=#1e3a5f;fontColor=#ffffff;fontStyle=1;fontSize=18;verticalAlign=middle;" value="JIT 编译优化过程" vertex="1">
<mxGeometry height="50" width="820" x="40" y="20" as="geometry" />
</mxCell>
<mxCell id="3" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#f8fafc;strokeColor=#cbd5e1;strokeWidth=2;" value="" vertex="1">
<mxGeometry height="640" width="820" x="40" y="80" as="geometry" />
</mxCell>
<mxCell id="4" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fef3c7;strokeColor=#f59e0b;fontColor=#92400e;fontSize=14;fontStyle=1;" value=".class 字节码" vertex="1">
<mxGeometry height="50" width="140" x="370" y="110" as="geometry" />
</mxCell>
<mxCell id="5" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;fontSize=24;" value="📄" vertex="1">
<mxGeometry height="40" width="40" x="330" y="115" as="geometry" />
</mxCell>
<mxCell id="6" edge="1" parent="1" source="4" style="edgeStyle=orthogonalEdgeStyle;strokeColor=#64748b;strokeWidth=2;endArrow=classic;endSize=10;" target="7">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="7" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#3b82f6;strokeColor=#2563eb;fontColor=#ffffff;fontStyle=1;fontSize=16;verticalAlign=top;spacingTop=10;" value="JVM 执行引擎" vertex="1">
<mxGeometry height="280" width="720" x="80" y="190" as="geometry" />
</mxCell>
<mxCell id="8" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dbeafe;strokeColor=#3b82f6;strokeWidth=2;" value="" vertex="1">
<mxGeometry height="220" width="180" x="100" y="230" as="geometry" />
</mxCell>
<mxCell id="9" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#93c5fd;strokeColor=#3b82f6;fontColor=#1e40af;fontSize=14;fontStyle=1;" value="🔄 解释器" vertex="1">
<mxGeometry height="40" width="150" x="115" y="245" as="geometry" />
</mxCell>
<mxCell id="10" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=left;verticalAlign=top;fontSize=12;fontColor=#1e40af;spacingLeft=5;" value="• 逐行解释执行
• 启动速度快
• 执行效率低
• 无需编译等待" vertex="1">
<mxGeometry height="90" width="150" x="115" y="295" as="geometry" />
</mxCell>
<mxCell id="11" parent="1" style="text;html=1;strokeColor=none;fillColor=#bfdbfe;align=center;verticalAlign=middle;fontSize=11;fontColor=#1e40af;rounded=1;" value="首次执行" vertex="1">
<mxGeometry height="25" width="100" x="140" y="400" as="geometry" />
</mxCell>
<mxCell id="12" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fef3c7;strokeColor=#f59e0b;strokeWidth=2;" value="" vertex="1">
<mxGeometry height="220" width="140" x="310" y="230" as="geometry" />
</mxCell>
<mxCell id="13" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fde047;strokeColor=#f59e0b;fontColor=#92400e;fontSize=14;fontStyle=1;" value="🔥 热点探测" vertex="1">
<mxGeometry height="40" width="120" x="320" y="245" as="geometry" />
</mxCell>
<mxCell id="14" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=top;fontSize=12;fontColor=#92400e;" value="方法调用计数器

回边计数器
(循环检测)" vertex="1">
<mxGeometry height="70" width="120" x="320" y="295" as="geometry" />
</mxCell>
<mxCell id="15" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fed7aa;strokeColor=#f59e0b;fontColor=#92400e;fontSize=12;fontStyle=1;" value="阈值触发" vertex="1">
<mxGeometry height="30" width="110" x="325" y="370" as="geometry" />
</mxCell>
<mxCell id="16" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;fontSize=11;fontColor=#92400e;fontStyle=1;" value="~10,000 次" vertex="1">
<mxGeometry height="25" width="100" x="330" y="405" as="geometry" />
</mxCell>
<mxCell id="17" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dcfce7;strokeColor=#22c55e;strokeWidth=2;" value="" vertex="1">
<mxGeometry height="220" width="300" x="480" y="230" as="geometry" />
</mxCell>
<mxCell id="18" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#86efac;strokeColor=#22c55e;fontColor=#166534;fontSize=14;fontStyle=1;" value="⚡ JIT 编译器" vertex="1">
<mxGeometry height="40" width="270" x="495" y="245" as="geometry" />
</mxCell>
<mxCell id="19" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#bbf7d0;strokeColor=#22c55e;fontColor=#166534;fontSize=12;fontStyle=1;" value="C1 (Client Compiler)" vertex="1">
<mxGeometry height="35" width="125" x="495" y="300" as="geometry" />
</mxCell>
<mxCell id="20" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=left;verticalAlign=top;fontSize=11;fontColor=#166534;" value="• 快速编译
• 简单优化
• 适合客户端" vertex="1">
<mxGeometry height="55" width="125" x="495" y="340" as="geometry" />
</mxCell>
<mxCell id="21" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#bbf7d0;strokeColor=#22c55e;fontColor=#166534;fontSize=12;fontStyle=1;" value="C2 (Server Compiler)" vertex="1">
<mxGeometry height="35" width="125" x="640" y="300" as="geometry" />
</mxCell>
<mxCell id="22" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=left;verticalAlign=top;fontSize=11;fontColor=#166534;" value="• 深度优化
• 编译慢执行快
• 适合服务端" vertex="1">
<mxGeometry height="55" width="125" x="640" y="340" as="geometry" />
</mxCell>
<mxCell id="23" parent="1" style="text;html=1;strokeColor=none;fillColor=#22c55e;align=center;verticalAlign=middle;fontSize=11;fontColor=#ffffff;rounded=1;fontStyle=1;" value="分层编译 (Tiered)" vertex="1">
<mxGeometry height="25" width="120" x="555" y="405" as="geometry" />
</mxCell>
<mxCell id="24" edge="1" parent="1" source="8" style="edgeStyle=orthogonalEdgeStyle;strokeColor=#f59e0b;strokeWidth=2;endArrow=classic;endSize=8;" target="12">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="25" connectable="0" parent="24" style="edgeLabel;html=1;align=center;verticalAlign=middle;fontSize=10;fontColor=#92400e;fillColor=#fef3c7;rounded=1;" value="热点代码" vertex="1">
<mxGeometry relative="1" x="-0.1" as="geometry">
<mxPoint as="offset" />
</mxGeometry>
</mxCell>
<mxCell id="26" edge="1" parent="1" source="12" style="edgeStyle=orthogonalEdgeStyle;strokeColor=#22c55e;strokeWidth=2;endArrow=classic;endSize=8;" target="17">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="27" connectable="0" parent="26" style="edgeLabel;html=1;align=center;verticalAlign=middle;fontSize=10;fontColor=#166534;fillColor=#dcfce7;rounded=1;" value="触发编译" vertex="1">
<mxGeometry relative="1" x="-0.1" as="geometry">
<mxPoint as="offset" />
</mxGeometry>
</mxCell>
<mxCell id="28" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#8b5cf6;strokeColor=#7c3aed;fontColor=#ffffff;fontSize=14;fontStyle=1;verticalAlign=top;spacingTop=10;" value="Code Cache (机器码缓存)" vertex="1">
<mxGeometry height="100" width="280" x="300" y="500" as="geometry" />
</mxCell>
<mxCell id="29" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;fontSize=12;fontColor=#ffffff;" value="💾 编译后的本地机器码
下次调用直接执行,无需重复编译" vertex="1">
<mxGeometry height="50" width="260" x="310" y="535" as="geometry" />
</mxCell>
<mxCell id="30" edge="1" parent="1" source="17" style="edgeStyle=orthogonalEdgeStyle;strokeColor=#8b5cf6;strokeWidth=2;endArrow=classic;endSize=10;" target="28">
<mxGeometry relative="1" as="geometry">
<Array as="points">
<mxPoint x="630" y="480" />
<mxPoint x="440" y="480" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="31" connectable="0" parent="30" style="edgeLabel;html=1;align=center;verticalAlign=middle;fontSize=10;fontColor=#7c3aed;fillColor=#ede9fe;rounded=1;" value="存储机器码" vertex="1">
<mxGeometry relative="1" x="0.2" as="geometry">
<mxPoint as="offset" />
</mxGeometry>
</mxCell>
<mxCell id="32" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;fontSize=13;fontStyle=1;fontColor=#475569;" value="执行性能对比" vertex="1">
<mxGeometry height="25" width="120" x="80" y="610" as="geometry" />
</mxCell>
<mxCell id="33" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#e2e8f0;strokeColor=#94a3b8;" value="" vertex="1">
<mxGeometry height="50" width="720" x="80" y="640" as="geometry" />
</mxCell>
<mxCell id="34" parent="1" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#93c5fd;strokeColor=#3b82f6;fontColor=#1e40af;fontSize=11;fontStyle=1;" value="解释执行 (慢)" vertex="1">
<mxGeometry height="30" width="100" x="90" y="650" as="geometry" />
</mxCell>
<mxCell id="35" parent="1" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#bbf7d0;strokeColor=#22c55e;fontColor=#166534;fontSize=11;fontStyle=1;" value="C1 编译 (中)" vertex="1">
<mxGeometry height="30" width="180" x="190" y="650" as="geometry" />
</mxCell>
<mxCell id="36" parent="1" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#86efac;strokeColor=#16a34a;fontColor=#166534;fontSize=11;fontStyle=1;" value="C2 编译 (快)" vertex="1">
<mxGeometry height="30" width="420" x="370" y="650" as="geometry" />
</mxCell>
<mxCell id="37" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;fontSize=18;" value="🚀" vertex="1">
<mxGeometry height="40" width="40" x="750" y="645" as="geometry" />
</mxCell>
<mxCell id="38" edge="1" parent="1" source="28" style="edgeStyle=orthogonalEdgeStyle;strokeColor=#8b5cf6;strokeWidth=2;endArrow=classic;dashed=1;dashPattern=8 8;" target="8">
<mxGeometry relative="1" as="geometry">
<Array as="points">
<mxPoint x="190" y="550" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="39" connectable="0" parent="38" style="edgeLabel;html=1;align=center;verticalAlign=middle;fontSize=10;fontColor=#7c3aed;fillColor=#ede9fe;rounded=1;" value="直接执行" vertex="1">
<mxGeometry relative="1" x="0.3" as="geometry">
<mxPoint as="offset" />
</mxGeometry>
</mxCell>
</root>
</mxGraphModel>
</diagram>
</mxfile>
JIT 优化技术示例
public class JITOptimizationDemo {
// 1. 方法内联(Inlining)
// JIT 会将短小方法直接嵌入调用处,减少方法调用开销
public int add(int a, int b) {
return a + b;
}
public int calculate() {
// JIT 优化后,add 方法会被内联
// return add(1, 2); → return 1 + 2; → return 3;
return add(1, 2);
}
// 2. 逃逸分析(Escape Analysis)
public void process() {
// point 对象未逃逸出方法,JIT 可能在栈上分配(标量替换)
Point point = new Point(1, 2);
int sum = point.x + point.y;
System.out.println(sum);
}
// 3. 循环优化
public int loopSum() {
int sum = 0;
for (int i = 0; i < 1000; i++) {
sum += i;
}
// JIT 可能进行循环展开、消除边界检查等优化
return sum;
}
}
2.8 特性总结表
| 特性 | 描述 | 核心优势 |
|---|---|---|
| 面向对象 | 封装、继承、多态 | 代码复用、结构清晰 |
| 跨平台 | JVM 屏蔽底层差异 | 一次编写,到处运行 |
| 多线程 | 语言原生支持 + 并发包 | 高效并发编程 |
| 自动 GC | 垃圾自动回收 | 降低内存泄漏风险 |
| 安全性 | 多层安全检查 | 类型安全、访问控制 |
| 高性能 | JIT 即时编译 | 接近原生代码性能 |
| 丰富类库 | 标准库 + 第三方生态 | 开发效率高 |
三、Java 平台版本体系
3.1 三大版本对比
<mxfile host="embed.diagrams.net" agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36" version="29.2.9">
<diagram id="java-platform-versions" name="Java 平台版本体系">
<mxGraphModel dx="1665" dy="798" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="900" pageHeight="750" math="0" shadow="0">
<root>
<mxCell id="0" />
<mxCell id="1" parent="0" />
<mxCell id="2" parent="1" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#1e3a5f;strokeColor=#1e3a5f;fontColor=#ffffff;fontStyle=1;fontSize=18;verticalAlign=middle;" value="Java 平台版本体系" vertex="1">
<mxGeometry height="50" width="820" x="40" y="20" as="geometry" />
</mxCell>
<mxCell id="3" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#f8fafc;strokeColor=#cbd5e1;strokeWidth=2;" value="" vertex="1">
<mxGeometry height="640" width="820" x="40" y="80" as="geometry" />
</mxCell>
<mxCell id="4" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fce7f3;strokeColor=#ec4899;fontColor=#9d174d;fontSize=14;fontStyle=1;" value="Java Card" vertex="1">
<mxGeometry height="50" width="140" x="380" y="100" as="geometry" />
</mxCell>
<mxCell id="5" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;fontSize=12;fontColor=#9d174d;" value="💳 智能卡(更精简)" vertex="1">
<mxGeometry height="30" width="150" x="535" y="110" as="geometry" />
</mxCell>
<mxCell id="6" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#e0f2fe;strokeColor=#0ea5e9;strokeWidth=2;" value="" vertex="1">
<mxGeometry height="400" width="700" x="100" y="190" as="geometry" />
</mxCell>
<mxCell id="7" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#8b5cf6;strokeColor=#7c3aed;fontColor=#ffffff;fontSize=15;fontStyle=1;verticalAlign=top;spacingTop=10;" value="Java EE / Jakarta EE" vertex="1">
<mxGeometry height="150" width="620" x="140" y="210" as="geometry" />
</mxCell>
<mxCell id="8" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#ede9fe;strokeColor=#8b5cf6;" value="" vertex="1">
<mxGeometry height="50" width="580" x="160" y="250" as="geometry" />
</mxCell>
<mxCell id="9" parent="1" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#c4b5fd;strokeColor=#8b5cf6;fontColor=#5b21b6;fontSize=11;fontStyle=1;" value="Servlet" vertex="1">
<mxGeometry height="30" width="70" x="170" y="260" as="geometry" />
</mxCell>
<mxCell id="10" parent="1" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#c4b5fd;strokeColor=#8b5cf6;fontColor=#5b21b6;fontSize=11;fontStyle=1;" value="JSP" vertex="1">
<mxGeometry height="30" width="60" x="250" y="260" as="geometry" />
</mxCell>
<mxCell id="11" parent="1" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#c4b5fd;strokeColor=#8b5cf6;fontColor=#5b21b6;fontSize=11;fontStyle=1;" value="JPA" vertex="1">
<mxGeometry height="30" width="60" x="320" y="260" as="geometry" />
</mxCell>
<mxCell id="12" parent="1" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#c4b5fd;strokeColor=#8b5cf6;fontColor=#5b21b6;fontSize=11;fontStyle=1;" value="EJB" vertex="1">
<mxGeometry height="30" width="60" x="390" y="260" as="geometry" />
</mxCell>
<mxCell id="13" parent="1" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#c4b5fd;strokeColor=#8b5cf6;fontColor=#5b21b6;fontSize=11;fontStyle=1;" value="JMS" vertex="1">
<mxGeometry height="30" width="60" x="460" y="260" as="geometry" />
</mxCell>
<mxCell id="14" parent="1" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#c4b5fd;strokeColor=#8b5cf6;fontColor=#5b21b6;fontSize=11;fontStyle=1;" value="JAX-RS" vertex="1">
<mxGeometry height="30" width="70" x="530" y="260" as="geometry" />
</mxCell>
<mxCell id="15" parent="1" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#c4b5fd;strokeColor=#8b5cf6;fontColor=#5b21b6;fontSize=11;fontStyle=1;" value="CDI" vertex="1">
<mxGeometry height="30" width="55" x="610" y="260" as="geometry" />
</mxCell>
<mxCell id="16" parent="1" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#c4b5fd;strokeColor=#8b5cf6;fontColor=#5b21b6;fontSize=11;fontStyle=1;" value="..." vertex="1">
<mxGeometry height="30" width="55" x="675" y="260" as="geometry" />
</mxCell>
<mxCell id="17" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;fontSize=12;fontColor=#5b21b6;fontStyle=1;" value="🏢 企业级规范 + API 扩展" vertex="1">
<mxGeometry height="30" width="200" x="340" y="310" as="geometry" />
</mxCell>
<mxCell id="18" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#22c55e;strokeColor=#16a34a;fontColor=#ffffff;fontSize=15;fontStyle=1;verticalAlign=top;spacingTop=10;" value="Java SE" vertex="1">
<mxGeometry height="190" width="620" x="140" y="380" as="geometry" />
</mxCell>
<mxCell id="19" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dcfce7;strokeColor=#22c55e;" value="" vertex="1">
<mxGeometry height="50" width="580" x="160" y="420" as="geometry" />
</mxCell>
<mxCell id="20" parent="1" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#86efac;strokeColor=#22c55e;fontColor=#166534;fontSize=11;fontStyle=1;" value="核心 API" vertex="1">
<mxGeometry height="30" width="70" x="170" y="430" as="geometry" />
</mxCell>
<mxCell id="21" parent="1" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#86efac;strokeColor=#22c55e;fontColor=#166534;fontSize=11;fontStyle=1;" value="集合框架" vertex="1">
<mxGeometry height="30" width="70" x="250" y="430" as="geometry" />
</mxCell>
<mxCell id="22" parent="1" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#86efac;strokeColor=#22c55e;fontColor=#166534;fontSize=11;fontStyle=1;" value="IO/NIO" vertex="1">
<mxGeometry height="30" width="65" x="330" y="430" as="geometry" />
</mxCell>
<mxCell id="23" parent="1" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#86efac;strokeColor=#22c55e;fontColor=#166534;fontSize=11;fontStyle=1;" value="网络" vertex="1">
<mxGeometry height="30" width="55" x="405" y="430" as="geometry" />
</mxCell>
<mxCell id="24" parent="1" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#86efac;strokeColor=#22c55e;fontColor=#166534;fontSize=11;fontStyle=1;" value="并发" vertex="1">
<mxGeometry height="30" width="55" x="470" y="430" as="geometry" />
</mxCell>
<mxCell id="25" parent="1" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#86efac;strokeColor=#22c55e;fontColor=#166534;fontSize=11;fontStyle=1;" value="JDBC" vertex="1">
<mxGeometry height="30" width="55" x="535" y="430" as="geometry" />
</mxCell>
<mxCell id="26" parent="1" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#86efac;strokeColor=#22c55e;fontColor=#166534;fontSize=11;fontStyle=1;" value="安全" vertex="1">
<mxGeometry height="30" width="55" x="600" y="430" as="geometry" />
</mxCell>
<mxCell id="27" parent="1" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#86efac;strokeColor=#22c55e;fontColor=#166534;fontSize=11;fontStyle=1;" value="..." vertex="1">
<mxGeometry height="30" width="55" x="665" y="430" as="geometry" />
</mxCell>
<mxCell id="28" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#bbf7d0;strokeColor=#22c55e;" value="" vertex="1">
<mxGeometry height="40" width="580" x="160" y="485" as="geometry" />
</mxCell>
<mxCell id="29" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;fontSize=12;fontColor=#166534;fontStyle=1;" value="⚙️ JVM (HotSpot/OpenJ9/GraalVM)" vertex="1">
<mxGeometry height="25" width="230" x="220" y="492" as="geometry" />
</mxCell>
<mxCell id="30" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;fontSize=12;fontColor=#166534;fontStyle=1;" value="🛠️ 开发工具 (javac/jar/jdb)" vertex="1">
<mxGeometry height="25" width="200" x="470" y="492" as="geometry" />
</mxCell>
<mxCell id="31" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;fontSize=12;fontColor=#166534;fontStyle=1;" value="📦 标准平台 - 桌面应用 & 服务端基础" vertex="1">
<mxGeometry height="25" width="280" x="300" y="535" as="geometry" />
</mxCell>
<mxCell id="32" edge="1" parent="1" source="18" style="edgeStyle=orthogonalEdgeStyle;strokeColor=#7c3aed;strokeWidth=2;endArrow=classic;endSize=8;" target="7">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="33" connectable="0" parent="32" style="edgeLabel;html=1;align=center;verticalAlign=middle;fontSize=11;fontColor=#7c3aed;fillColor=#ede9fe;rounded=1;" value="基于" vertex="1">
<mxGeometry relative="1" x="0.1" as="geometry">
<mxPoint as="offset" />
</mxGeometry>
</mxCell>
<mxCell id="34" edge="1" parent="1" style="edgeStyle=orthogonalEdgeStyle;strokeColor=#ec4899;strokeWidth=2;endArrow=classic;endSize=8;" target="4">
<mxGeometry relative="1" as="geometry">
<Array as="points">
<mxPoint x="450" y="180" />
</Array>
<mxPoint x="450" y="190" as="sourcePoint" />
</mxGeometry>
</mxCell>
<mxCell id="35" connectable="0" parent="34" style="edgeLabel;html=1;align=center;verticalAlign=middle;fontSize=11;fontColor=#ec4899;fillColor=#fce7f3;rounded=1;" value="精简" vertex="1">
<mxGeometry relative="1" x="0.2" as="geometry">
<mxPoint as="offset" />
</mxGeometry>
</mxCell>
<mxCell id="36" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fef3c7;strokeColor=#f59e0b;fontColor=#92400e;fontSize=14;fontStyle=1;" value="Java ME (精简版)" vertex="1">
<mxGeometry height="50" width="160" x="80" y="620" as="geometry" />
</mxCell>
<mxCell id="37" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;fontSize=12;fontColor=#92400e;" value="📱 嵌入式/移动设备" vertex="1">
<mxGeometry height="25" width="140" x="260" y="620" as="geometry" />
</mxCell>
<mxCell id="38" parent="1" style="text;html=1;strokeColor=none;fillColor=#fee2e2;align=left;verticalAlign=middle;fontSize=11;fontColor=#991b1b;rounded=1;" value="⚠️ 已淘汰 (被 Android 取代)" vertex="1">
<mxGeometry height="25" width="170" x="260" y="645" as="geometry" />
</mxCell>
<mxCell id="39" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;fontSize=13;fontStyle=1;fontColor=#475569;" value="版本关系说明" vertex="1">
<mxGeometry height="25" width="120" x="497.5" y="600" as="geometry" />
</mxCell>
<mxCell id="40" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#f1f5f9;strokeColor=#94a3b8;" value="" vertex="1">
<mxGeometry height="70" width="280" x="497.5" y="630" as="geometry" />
</mxCell>
<mxCell id="41" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;fontSize=11;fontColor=#475569;spacingLeft=10;" value="SE = Standard Edition (标准版)
EE = Enterprise Edition (企业版)
ME = Micro Edition (微型版)" vertex="1">
<mxGeometry height="60" width="260" x="505" y="635" as="geometry" />
</mxCell>
</root>
</mxGraphModel>
</diagram>
</mxfile>
3.2 详细对比
| 版本 | 全称 | 定位 | 包含内容 | 应用场景 |
|---|---|---|---|---|
| Java SE | Standard Edition | 标准版 | JVM + 核心类库 + 开发工具 | 桌面应用、简单服务端 |
| Java EE | Enterprise Edition | 企业版 | SE + 企业级规范(Servlet/JPA/EJB...) | 大型分布式系统 |
| Java ME | Micro Edition | 微型版 | 精简版 SE | 嵌入式设备(已淘汰) |
3.3 Java SE 核心组成
// Java SE 提供的核心 API 示例
// 1. 集合框架 (java.util)
import java.util.ArrayList;
import java.util.HashMap;
// 2. IO/NIO (java.io, java.nio)
import java.io.FileInputStream;
import java.nio.file.Files;
// 3. 网络编程 (java.net)
import java.net.Socket;
import java.net.HttpURLConnection;
// 4. 并发编程 (java.util.concurrent)
import java.util.concurrent.ExecutorService;
import java.util.concurrent.CompletableFuture;
// 5. 时间日期 (java.time) - Java 8+
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
// 6. 反射 (java.lang.reflect)
import java.lang.reflect.Method;
import java.lang.reflect.Field;
3.4 Java EE 核心规范
<mxfile>
<diagram id="java-ee-jakarta-ee-specs" name="Java EE / Jakarta EE 核心规范">
<mxGraphModel dx="900" dy="700" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="900" pageHeight="700">
<root>
<mxCell id="0" />
<mxCell id="1" parent="0" />
<mxCell id="2" value="Java EE / Jakarta EE 核心规范" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#7c3aed;strokeColor=#7c3aed;fontColor=#ffffff;fontStyle=1;fontSize=18;verticalAlign=middle;" vertex="1" parent="1">
<mxGeometry x="40" y="30" width="820" height="50" as="geometry" />
</mxCell>
<mxCell id="3" value="" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#faf5ff;strokeColor=#c4b5fd;strokeWidth=2;" vertex="1" parent="1">
<mxGeometry x="40" y="80" width="820" height="590" as="geometry" />
</mxCell>
<mxCell id="4" value="Web 层" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#3b82f6;strokeColor=#2563eb;fontColor=#ffffff;fontSize=14;fontStyle=1;verticalAlign=top;spacingTop=8;" vertex="1" parent="1">
<mxGeometry x="70" y="110" width="230" height="180" as="geometry" />
</mxCell>
<mxCell id="5" value="Servlet" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dbeafe;strokeColor=#3b82f6;fontColor=#1e40af;fontSize=12;fontStyle=1;" vertex="1" parent="1">
<mxGeometry x="85" y="145" width="95" height="32" as="geometry" />
</mxCell>
<mxCell id="6" value="JSP" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dbeafe;strokeColor=#3b82f6;fontColor=#1e40af;fontSize=12;fontStyle=1;" vertex="1" parent="1">
<mxGeometry x="190" y="145" width="95" height="32" as="geometry" />
</mxCell>
<mxCell id="7" value="JSF" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dbeafe;strokeColor=#3b82f6;fontColor=#1e40af;fontSize=12;fontStyle=1;" vertex="1" parent="1">
<mxGeometry x="85" y="187" width="95" height="32" as="geometry" />
</mxCell>
<mxCell id="8" value="JAX-RS" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dbeafe;strokeColor=#3b82f6;fontColor=#1e40af;fontSize=12;fontStyle=1;" vertex="1" parent="1">
<mxGeometry x="190" y="187" width="95" height="32" as="geometry" />
</mxCell>
<mxCell id="9" value="WebSocket" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dbeafe;strokeColor=#3b82f6;fontColor=#1e40af;fontSize=12;fontStyle=1;" vertex="1" parent="1">
<mxGeometry x="85" y="229" width="200" height="32" as="geometry" />
</mxCell>
<mxCell id="10" value="🌐" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;fontSize=20;" vertex="1" parent="1">
<mxGeometry x="255" y="105" width="35" height="35" as="geometry" />
</mxCell>
<mxCell id="11" value="业务层" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#22c55e;strokeColor=#16a34a;fontColor=#ffffff;fontSize=14;fontStyle=1;verticalAlign=top;spacingTop=8;" vertex="1" parent="1">
<mxGeometry x="335" y="110" width="230" height="180" as="geometry" />
</mxCell>
<mxCell id="12" value="EJB" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dcfce7;strokeColor=#22c55e;fontColor=#166534;fontSize=12;fontStyle=1;" vertex="1" parent="1">
<mxGeometry x="350" y="145" width="200" height="32" as="geometry" />
</mxCell>
<mxCell id="13" value="CDI" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dcfce7;strokeColor=#22c55e;fontColor=#166534;fontSize=12;fontStyle=1;" vertex="1" parent="1">
<mxGeometry x="350" y="187" width="200" height="32" as="geometry" />
</mxCell>
<mxCell id="14" value="JTA" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dcfce7;strokeColor=#22c55e;fontColor=#166534;fontSize=12;fontStyle=1;" vertex="1" parent="1">
<mxGeometry x="350" y="229" width="200" height="32" as="geometry" />
</mxCell>
<mxCell id="15" value="⚙️" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;fontSize=20;" vertex="1" parent="1">
<mxGeometry x="520" y="105" width="35" height="35" as="geometry" />
</mxCell>
<mxCell id="16" value="持久层" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#f59e0b;strokeColor=#d97706;fontColor=#ffffff;fontSize=14;fontStyle=1;verticalAlign=top;spacingTop=8;" vertex="1" parent="1">
<mxGeometry x="600" y="110" width="230" height="180" as="geometry" />
</mxCell>
<mxCell id="17" value="JPA" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fef3c7;strokeColor=#f59e0b;fontColor=#92400e;fontSize=12;fontStyle=1;" vertex="1" parent="1">
<mxGeometry x="615" y="145" width="200" height="32" as="geometry" />
</mxCell>
<mxCell id="18" value="JDBC" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fef3c7;strokeColor=#f59e0b;fontColor=#92400e;fontSize=12;fontStyle=1;" vertex="1" parent="1">
<mxGeometry x="615" y="187" width="200" height="32" as="geometry" />
</mxCell>
<mxCell id="19" value="JCA" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fef3c7;strokeColor=#f59e0b;fontColor=#92400e;fontSize=12;fontStyle=1;" vertex="1" parent="1">
<mxGeometry x="615" y="229" width="200" height="32" as="geometry" />
</mxCell>
<mxCell id="20" value="💾" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;fontSize=20;" vertex="1" parent="1">
<mxGeometry x="785" y="105" width="35" height="35" as="geometry" />
</mxCell>
<mxCell id="21" value="消息服务" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#ec4899;strokeColor=#db2777;fontColor=#ffffff;fontSize=14;fontStyle=1;verticalAlign=top;spacingTop=8;" vertex="1" parent="1">
<mxGeometry x="70" y="320" width="230" height="130" as="geometry" />
</mxCell>
<mxCell id="22" value="JMS" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fce7f3;strokeColor=#ec4899;fontColor=#9d174d;fontSize=12;fontStyle=1;" vertex="1" parent="1">
<mxGeometry x="85" y="355" width="200" height="32" as="geometry" />
</mxCell>
<mxCell id="23" value="异步消息传递" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;fontSize=11;fontColor=#9d174d;fontStyle=2;" vertex="1" parent="1">
<mxGeometry x="85" y="395" width="200" height="25" as="geometry" />
</mxCell>
<mxCell id="24" value="📨" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;fontSize=20;" vertex="1" parent="1">
<mxGeometry x="255" y="315" width="35" height="35" as="geometry" />
</mxCell>
<mxCell id="25" value="安全" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#ef4444;strokeColor=#dc2626;fontColor=#ffffff;fontSize=14;fontStyle=1;verticalAlign=top;spacingTop=8;" vertex="1" parent="1">
<mxGeometry x="335" y="320" width="230" height="130" as="geometry" />
</mxCell>
<mxCell id="26" value="JAAS" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fee2e2;strokeColor=#ef4444;fontColor=#991b1b;fontSize=12;fontStyle=1;" vertex="1" parent="1">
<mxGeometry x="350" y="355" width="95" height="32" as="geometry" />
</mxCell>
<mxCell id="27" value="JASPIC" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fee2e2;strokeColor=#ef4444;fontColor=#991b1b;fontSize=12;fontStyle=1;" vertex="1" parent="1">
<mxGeometry x="455" y="355" width="95" height="32" as="geometry" />
</mxCell>
<mxCell id="28" value="认证 & 授权" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;fontSize=11;fontColor=#991b1b;fontStyle=2;" vertex="1" parent="1">
<mxGeometry x="350" y="395" width="200" height="25" as="geometry" />
</mxCell>
<mxCell id="29" value="🔒" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;fontSize=20;" vertex="1" parent="1">
<mxGeometry x="520" y="315" width="35" height="35" as="geometry" />
</mxCell>
<mxCell id="30" value="其他" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#8b5cf6;strokeColor=#7c3aed;fontColor=#ffffff;fontSize=14;fontStyle=1;verticalAlign=top;spacingTop=8;" vertex="1" parent="1">
<mxGeometry x="600" y="320" width="230" height="130" as="geometry" />
</mxCell>
<mxCell id="31" value="JSON-P" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#ede9fe;strokeColor=#8b5cf6;fontColor=#5b21b6;fontSize=12;fontStyle=1;" vertex="1" parent="1">
<mxGeometry x="615" y="355" width="95" height="32" as="geometry" />
</mxCell>
<mxCell id="32" value="JSON-B" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#ede9fe;strokeColor=#8b5cf6;fontColor=#5b21b6;fontSize=12;fontStyle=1;" vertex="1" parent="1">
<mxGeometry x="720" y="355" width="95" height="32" as="geometry" />
</mxCell>
<mxCell id="33" value="Bean Validation" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#ede9fe;strokeColor=#8b5cf6;fontColor=#5b21b6;fontSize=12;fontStyle=1;" vertex="1" parent="1">
<mxGeometry x="615" y="397" width="200" height="32" as="geometry" />
</mxCell>
<mxCell id="34" value="📦" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;fontSize=20;" vertex="1" parent="1">
<mxGeometry x="785" y="315" width="35" height="35" as="geometry" />
</mxCell>
<mxCell id="35" value="" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fef3c7;strokeColor=#f59e0b;strokeWidth=2;" vertex="1" parent="1">
<mxGeometry x="70" y="480" width="760" height="170" as="geometry" />
</mxCell>
<mxCell id="36" value="📋 历史演变说明" style="text;html=1;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;fontSize=14;fontStyle=1;fontColor=#92400e;" vertex="1" parent="1">
<mxGeometry x="90" y="490" width="150" height="30" as="geometry" />
</mxCell>
<mxCell id="37" value="" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#ffffff;strokeColor=#f59e0b;" vertex="1" parent="1">
<mxGeometry x="90" y="525" width="320" height="110" as="geometry" />
</mxCell>
<mxCell id="38" value="2017 年之前" style="text;html=1;strokeColor=none;fillColor=#f59e0b;align=center;verticalAlign=middle;fontSize=12;fontStyle=1;fontColor=#ffffff;rounded=1;" vertex="1" parent="1">
<mxGeometry x="100" y="535" width="100" height="25" as="geometry" />
</mxCell>
<mxCell id="39" value="Java EE (Oracle 维护)

包名: javax.*
如: javax.servlet.http" style="text;html=1;strokeColor=none;fillColor=none;align=left;verticalAlign=top;fontSize=12;fontColor=#92400e;spacingLeft=5;" vertex="1" parent="1">
<mxGeometry x="100" y="565" width="200" height="65" as="geometry" />
</mxCell>
<mxCell id="40" value="" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#ffffff;strokeColor=#22c55e;" vertex="1" parent="1">
<mxGeometry x="490" y="525" width="320" height="110" as="geometry" />
</mxCell>
<mxCell id="41" value="2017 年之后" style="text;html=1;strokeColor=none;fillColor=#22c55e;align=center;verticalAlign=middle;fontSize=12;fontStyle=1;fontColor=#ffffff;rounded=1;" vertex="1" parent="1">
<mxGeometry x="500" y="535" width="100" height="25" as="geometry" />
</mxCell>
<mxCell id="42" value="Jakarta EE (Eclipse 基金会)

包名: jakarta.*
如: jakarta.servlet.http" style="text;html=1;strokeColor=none;fillColor=none;align=left;verticalAlign=top;fontSize=12;fontColor=#166534;spacingLeft=5;" vertex="1" parent="1">
<mxGeometry x="500" y="565" width="220" height="65" as="geometry" />
</mxCell>
<mxCell id="43" style="edgeStyle=orthogonalEdgeStyle;strokeColor=#64748b;strokeWidth=3;endArrow=classic;endSize=12;" edge="1" parent="1" source="37" target="40">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="44" value="移交" style="edgeLabel;html=1;align=center;verticalAlign=middle;fontSize=11;fontColor=#ffffff;fillColor=#64748b;rounded=1;" vertex="1" connectable="0" parent="43">
<mxGeometry x="-0.05" relative="1" as="geometry">
<mxPoint as="offset" />
</mxGeometry>
</mxCell>
</root>
</mxGraphModel>
</diagram>
</mxfile>
// Java EE 应用示例 - Servlet
// Java EE (javax)
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
// Jakarta EE (jakarta) - 新版
import jakarta.servlet.http.HttpServlet;
@WebServlet("/hello")
public class HelloServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
resp.setContentType("text/html;charset=UTF-8");
resp.getWriter().write("<h1>Hello, Java EE!</h1>");
}
}
3.5 版本选择指南
<mxfile host="embed.diagrams.net" agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36" version="29.2.9">
<diagram id="java-version-selection-guide" name="如何选择 Java 版本">
<mxGraphModel dx="1665" dy="798" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="900" pageHeight="750" math="0" shadow="0">
<root>
<mxCell id="0" />
<mxCell id="1" parent="0" />
<mxCell id="2" parent="1" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#1e40af;strokeColor=#1e40af;fontColor=#ffffff;fontStyle=1;fontSize=20;verticalAlign=middle;" value="如何选择 Java 版本?" vertex="1">
<mxGeometry height="50" width="820" x="40" y="20" as="geometry" />
</mxCell>
<mxCell id="3" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#f8fafc;strokeColor=#cbd5e1;strokeWidth=2;" value="" vertex="1">
<mxGeometry height="650" width="820" x="40" y="80" as="geometry" />
</mxCell>
<mxCell id="4" parent="1" style="ellipse;whiteSpace=wrap;html=1;fillColor=#7c3aed;strokeColor=#6d28d9;fontColor=#ffffff;fontSize=16;fontStyle=1;" value="需求分析" vertex="1">
<mxGeometry height="60" width="120" x="95" y="140" as="geometry" />
</mxCell>
<mxCell id="5" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#e0f2fe;strokeColor=#0ea5e9;fontColor=#0369a1;fontSize=12;fontStyle=1;" value="命令行工具 / 桌面应用 / 简单后端" vertex="1">
<mxGeometry height="45" width="240" x="70" y="210" as="geometry" />
</mxCell>
<mxCell id="6" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#22c55e;strokeColor=#16a34a;fontColor=#ffffff;fontSize=14;fontStyle=1;" value="Java SE" vertex="1">
<mxGeometry height="45" width="140" x="680" y="210" as="geometry" />
</mxCell>
<mxCell id="7" edge="1" parent="1" source="5" style="edgeStyle=orthogonalEdgeStyle;strokeColor=#0ea5e9;strokeWidth=2;endArrow=classic;endSize=10;" target="6">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="8" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fef3c7;strokeColor=#f59e0b;fontColor=#92400e;fontSize=12;fontStyle=1;" value="企业级 Web 应用" vertex="1">
<mxGeometry height="45" width="150" x="70" y="290" as="geometry" />
</mxCell>
<mxCell id="9" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dcfce7;strokeColor=#22c55e;fontColor=#166534;fontSize=12;fontStyle=1;" value="使用 Spring Boot" vertex="1">
<mxGeometry height="45" width="150" x="260" y="290" as="geometry" />
</mxCell>
<mxCell id="10" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#22c55e;strokeColor=#16a34a;fontColor=#ffffff;fontSize=13;fontStyle=1;" value="Java SE + Spring 生态" vertex="1">
<mxGeometry height="45" width="140" x="680" y="290" as="geometry" />
</mxCell>
<mxCell id="11" edge="1" parent="1" source="9" style="edgeStyle=orthogonalEdgeStyle;strokeColor=#22c55e;strokeWidth=2;endArrow=classic;endSize=10;" target="10">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="12" parent="1" style="text;html=1;strokeColor=none;fillColor=#22c55e;align=center;verticalAlign=middle;fontSize=11;fontColor=#ffffff;rounded=1;fontStyle=1;" value="⭐ 推荐" vertex="1">
<mxGeometry height="20" width="50" x="415" y="295" as="geometry" />
</mxCell>
<mxCell id="13" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;fontSize=11;fontColor=#166534;fontStyle=2;" value="内嵌服务器,更轻量" vertex="1">
<mxGeometry height="20" width="140" x="260" y="335" as="geometry" />
</mxCell>
<mxCell id="14" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fee2e2;strokeColor=#ef4444;fontColor=#991b1b;fontSize=12;fontStyle=1;" value="传统 Java EE 应用" vertex="1">
<mxGeometry height="45" width="150" x="260" y="390" as="geometry" />
</mxCell>
<mxCell id="15" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#f59e0b;strokeColor=#d97706;fontColor=#ffffff;fontSize=12;fontStyle=1;" value="Jakarta EE + 应用服务器" vertex="1">
<mxGeometry height="45" width="140" x="680" y="390" as="geometry" />
</mxCell>
<mxCell id="16" edge="1" parent="1" source="14" style="edgeStyle=orthogonalEdgeStyle;strokeColor=#ef4444;strokeWidth=2;endArrow=classic;endSize=10;" target="15">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="17" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;fontSize=11;fontColor=#991b1b;fontStyle=2;" value="如 Tomcat, WildFly, WebLogic" vertex="1">
<mxGeometry height="20" width="200" x="260" y="435" as="geometry" />
</mxCell>
<mxCell id="18" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#ede9fe;strokeColor=#8b5cf6;fontColor=#5b21b6;fontSize=12;fontStyle=1;" value="微服务 / 云原生" vertex="1">
<mxGeometry height="45" width="150" x="70" y="490" as="geometry" />
</mxCell>
<mxCell id="19" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#8b5cf6;strokeColor=#7c3aed;fontColor=#ffffff;fontSize=12;fontStyle=1;" value="Java SE + Spring Cloud
或 Quarkus / Micronaut" vertex="1">
<mxGeometry height="65" width="140" x="680" y="480" as="geometry" />
</mxCell>
<mxCell id="20" edge="1" parent="1" source="18" style="edgeStyle=orthogonalEdgeStyle;strokeColor=#8b5cf6;strokeWidth=2;endArrow=classic;endSize=10;" target="19">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="21" edge="1" parent="1" source="4" style="edgeStyle=orthogonalEdgeStyle;strokeColor=#7c3aed;strokeWidth=2;endArrow=none;endFill=0;" target="5">
<mxGeometry relative="1" as="geometry">
<Array as="points">
<mxPoint x="50" y="170" />
<mxPoint x="50" y="233" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="22" edge="1" parent="1" source="4" style="edgeStyle=orthogonalEdgeStyle;strokeColor=#7c3aed;strokeWidth=2;endArrow=none;endFill=0;" target="8">
<mxGeometry relative="1" as="geometry">
<Array as="points">
<mxPoint x="50" y="170" />
<mxPoint x="50" y="313" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="23" edge="1" parent="1" source="4" style="edgeStyle=orthogonalEdgeStyle;strokeColor=#7c3aed;strokeWidth=2;endArrow=none;endFill=0;exitX=0;exitY=0.5;exitDx=0;exitDy=0;" target="18">
<mxGeometry relative="1" as="geometry">
<Array as="points">
<mxPoint x="95" y="170" />
<mxPoint x="50" y="170" />
<mxPoint x="50" y="513" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="24" edge="1" parent="1" source="8" style="edgeStyle=orthogonalEdgeStyle;strokeColor=#f59e0b;strokeWidth=2;endArrow=none;endFill=0;" target="9">
<mxGeometry relative="1" as="geometry">
<Array as="points">
<mxPoint x="240" y="313" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="25" edge="1" parent="1" source="8" style="edgeStyle=orthogonalEdgeStyle;strokeColor=#f59e0b;strokeWidth=2;endArrow=none;endFill=0;" target="14">
<mxGeometry relative="1" as="geometry">
<Array as="points">
<mxPoint x="240" y="335" />
<mxPoint x="240" y="413" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="26" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dbeafe;strokeColor=#3b82f6;strokeWidth=2;" value="" vertex="1">
<mxGeometry height="120" width="750" x="70" y="580" as="geometry" />
</mxCell>
<mxCell id="27" parent="1" style="text;html=1;strokeColor=none;fillColor=#3b82f6;align=center;verticalAlign=middle;fontSize=14;fontStyle=1;fontColor=#ffffff;rounded=1;" value="💡 现代开发建议" vertex="1">
<mxGeometry height="30" width="130" x="90" y="595" as="geometry" />
</mxCell>
<mxCell id="28" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;fontSize=14;fontColor=#1e40af;" value="大多数场景选择" vertex="1">
<mxGeometry height="30" width="120" x="90" y="640" as="geometry" />
</mxCell>
<mxCell id="29" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#22c55e;strokeColor=#16a34a;fontColor=#ffffff;fontSize=14;fontStyle=1;" value="Java SE + Spring Boot" vertex="1">
<mxGeometry height="35" width="180" x="210" y="640" as="geometry" />
</mxCell>
<mxCell id="30" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;fontSize=14;fontColor=#1e40af;" value="即可,无需直接使用 Java EE 规范" vertex="1">
<mxGeometry height="30" width="250" x="400" y="640" as="geometry" />
</mxCell>
<mxCell id="31" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;fontSize=12;fontColor=#166534;fontStyle=1;" value="✓ 开发效率高" vertex="1">
<mxGeometry height="25" width="100" x="660" y="595" as="geometry" />
</mxCell>
<mxCell id="32" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;fontSize=12;fontColor=#166534;fontStyle=1;" value="✓ 生态完善" vertex="1">
<mxGeometry height="25" width="100" x="660" y="620" as="geometry" />
</mxCell>
<mxCell id="33" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;fontSize=12;fontColor=#166534;fontStyle=1;" value="✓ 部署简单" vertex="1">
<mxGeometry height="25" width="100" x="660" y="645" as="geometry" />
</mxCell>
<mxCell id="34" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;fontSize=12;fontColor=#166534;fontStyle=1;" value="✓ 社区活跃" vertex="1">
<mxGeometry height="25" width="100" x="660" y="670" as="geometry" />
</mxCell>
<mxCell id="35" parent="1" style="verticalLabelPosition=bottom;verticalAlign=top;html=1;shape=mxgraph.basic.tick;fillColor=#22c55e;strokeColor=#16a34a;" value="" vertex="1">
<mxGeometry height="40" width="40" x="770" y="620" as="geometry" />
</mxCell>
</root>
</mxGraphModel>
</diagram>
</mxfile>
四、Java 与 C++ 深度对比
4.1 总体对比表
| 对比维度 | Java | C++ |
|---|---|---|
| 设计理念 | 简单、安全、跨平台 | 高效、灵活、接近底层 |
| 编译执行 | 编译成字节码,JVM 解释/JIT执行 | 直接编译成机器码 |
| 内存管理 | 自动 GC,无需手动释放 | 手动 new/delete,或智能指针 |
| 指针操作 | 不支持指针,只有引用 | 完全支持指针运算 |
| 多重继承 | 单继承 + 多接口实现 | 支持多重继承 |
| 运算符重载 | 不支持 | 支持 |
| 泛型实现 | 类型擦除(编译期) | 模板(编译期代码膨胀) |
| 预处理器 | 无 | 有(#define, #include) |
| 跨平台 | JVM 保证 | 需重新编译 |
| 性能 | 略低于 C++(JIT 优化后接近) | 最高(直接机器码) |
4.2 代码对比示例
内存管理
// ==================== C++ ====================
#include <iostream>
#include <memory>
class Person {
public:
std::string name;
Person(std::string n) : name(n) {
std::cout << "Person created: " << name << std::endl;
}
~Person() { // 析构函数
std::cout << "Person destroyed: " << name << std::endl;
}
};
int main() {
// 方式1: 手动管理(容易出错)
Person* p1 = new Person("Alice");
delete p1; // 必须手动释放!
// 方式2: 智能指针(推荐)
std::unique_ptr<Person> p2 = std::make_unique<Person>("Bob");
// 作用域结束自动释放
return 0;
}
// ==================== Java ====================
public class Person {
private String name;
public Person(String name) {
this.name = name;
System.out.println("Person created: " + name);
}
// finalize 已被弃用,不推荐使用
// Java 9+ 推荐使用 Cleaner
public static void main(String[] args) {
Person p1 = new Person("Alice");
Person p2 = new Person("Bob");
p1 = null; // 解除引用
// GC 会在适当时机自动回收
System.gc(); // 建议 GC 运行(不保证立即执行)
}
}
继承机制
// ==================== C++ 多重继承 ====================
class Flyable {
public:
virtual void fly() { std::cout << "Flying" << std::endl; }
};
class Swimmable {
public:
virtual void swim() { std::cout << "Swimming" << std::endl; }
};
// C++ 支持多重继承
class Duck : public Flyable, public Swimmable {
public:
void fly() override { std::cout << "Duck flying" << std::endl; }
void swim() override { std::cout << "Duck swimming" << std::endl; }
};
// ==================== Java 单继承 + 多接口 ====================
interface Flyable {
default void fly() { // Java 8+ 接口默认方法
System.out.println("Flying");
}
}
interface Swimmable {
default void swim() {
System.out.println("Swimming");
}
}
// Java 单继承,但可实现多个接口
class Duck extends Animal implements Flyable, Swimmable {
@Override
public void fly() {
System.out.println("Duck flying");
}
@Override
public void swim() {
System.out.println("Duck swimming");
}
}
泛型实现差异
// ==================== C++ 模板 ====================
template<typename T>
class Box {
private:
T value;
public:
void set(T v) { value = v; }
T get() { return value; }
};
int main() {
Box<int> intBox; // 编译时生成 Box<int> 的代码
Box<double> doubleBox; // 编译时生成 Box<double> 的代码
// 代码膨胀:每种类型生成独立的代码
}
// ==================== Java 泛型(类型擦除)====================
public class Box<T> {
private T value;
public void set(T v) { value = v; }
public T get() { return value; }
}
public class Main {
public static void main(String[] args) {
Box<Integer> intBox = new Box<>();
Box<Double> doubleBox = new Box<>();
// 运行时类型信息被擦除
System.out.println(intBox.getClass() == doubleBox.getClass()); // true
// 编译后实际是:
// class Box { Object value; ... }
}
}
4.3 应用场景对比
<mxfile>
<diagram id="java-cpp-comparison" name="应用场景选择">
<mxGraphModel dx="1665" dy="798" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="900" pageHeight="700" math="0" shadow="0">
<root>
<mxCell id="0" />
<mxCell id="1" parent="0" />
<mxCell id="2" parent="1" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#1e293b;strokeColor=#1e293b;fontColor=#ffffff;fontStyle=1;fontSize=20;verticalAlign=middle;" value="应用场景选择" vertex="1">
<mxGeometry height="50" width="820" x="40" y="30" as="geometry" />
</mxCell>
<mxCell id="3" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#f8fafc;strokeColor=#e2e8f0;strokeWidth=2;" value="" vertex="1">
<mxGeometry height="600" width="820" x="40" y="80" as="geometry" />
</mxCell>
<mxCell id="4" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dbeafe;strokeColor=#3b82f6;strokeWidth=2;" value="" vertex="1">
<mxGeometry height="340" width="380" x="60" y="100" as="geometry" />
</mxCell>
<mxCell id="5" parent="1" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#3b82f6;strokeColor=#2563eb;fontColor=#ffffff;fontStyle=1;fontSize=16;verticalAlign=middle;" value="☕ Java 更适合" vertex="1">
<mxGeometry height="45" width="380" x="60" y="100" as="geometry" />
</mxCell>
<mxCell id="6" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fce7f3;strokeColor=#ec4899;strokeWidth=2;" value="" vertex="1">
<mxGeometry height="340" width="380" x="460" y="100" as="geometry" />
</mxCell>
<mxCell id="7" parent="1" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#ec4899;strokeColor=#db2777;fontColor=#ffffff;fontStyle=1;fontSize=16;verticalAlign=middle;" value="⚡ C++ 更适合" vertex="1">
<mxGeometry height="45" width="380" x="460" y="100" as="geometry" />
</mxCell>
<mxCell id="8" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#ffffff;strokeColor=#3b82f6;fontColor=#1e40af;fontSize=13;fontStyle=1;align=left;spacingLeft=15;" value="企业级 Web 应用" vertex="1">
<mxGeometry height="36" width="340" x="80" y="160" as="geometry" />
</mxCell>
<mxCell id="9" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#ffffff;strokeColor=#3b82f6;fontColor=#1e40af;fontSize=13;fontStyle=1;align=left;spacingLeft=15;" value="分布式系统 / 微服务" vertex="1">
<mxGeometry height="36" width="340" x="80" y="204" as="geometry" />
</mxCell>
<mxCell id="10" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#ffffff;strokeColor=#3b82f6;fontColor=#1e40af;fontSize=13;fontStyle=1;align=left;spacingLeft=15;" value="Android 应用开发" vertex="1">
<mxGeometry height="36" width="340" x="80" y="248" as="geometry" />
</mxCell>
<mxCell id="11" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#ffffff;strokeColor=#3b82f6;fontColor=#1e40af;fontSize=13;fontStyle=1;align=left;spacingLeft=15;" value="大数据处理(Hadoop / Spark)" vertex="1">
<mxGeometry height="36" width="340" x="80" y="292" as="geometry" />
</mxCell>
<mxCell id="12" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#ffffff;strokeColor=#3b82f6;fontColor=#1e40af;fontSize=13;fontStyle=1;align=left;spacingLeft=15;" value="云平台服务" vertex="1">
<mxGeometry height="36" width="340" x="80" y="336" as="geometry" />
</mxCell>
<mxCell id="13" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#ffffff;strokeColor=#3b82f6;fontColor=#1e40af;fontSize=13;fontStyle=1;align=left;spacingLeft=15;" value="金融业务系统" vertex="1">
<mxGeometry height="36" width="340" x="80" y="380" as="geometry" />
</mxCell>
<mxCell id="14" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#ffffff;strokeColor=#ec4899;fontColor=#9d174d;fontSize=13;fontStyle=1;align=left;spacingLeft=15;" value="操作系统、驱动程序" vertex="1">
<mxGeometry height="36" width="340" x="480" y="160" as="geometry" />
</mxCell>
<mxCell id="15" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#ffffff;strokeColor=#ec4899;fontColor=#9d174d;fontSize=13;fontStyle=1;align=left;spacingLeft=15;" value="游戏引擎(Unity底层、Unreal)" vertex="1">
<mxGeometry height="36" width="340" x="480" y="204" as="geometry" />
</mxCell>
<mxCell id="16" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#ffffff;strokeColor=#ec4899;fontColor=#9d174d;fontSize=13;fontStyle=1;align=left;spacingLeft=15;" value="嵌入式系统" vertex="1">
<mxGeometry height="36" width="340" x="480" y="248" as="geometry" />
</mxCell>
<mxCell id="17" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#ffffff;strokeColor=#ec4899;fontColor=#9d174d;fontSize=13;fontStyle=1;align=left;spacingLeft=15;" value="高频交易系统" vertex="1">
<mxGeometry height="36" width="340" x="480" y="292" as="geometry" />
</mxCell>
<mxCell id="18" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#ffffff;strokeColor=#ec4899;fontColor=#9d174d;fontSize=13;fontStyle=1;align=left;spacingLeft=15;" value="数据库内核(MySQL、Redis)" vertex="1">
<mxGeometry height="36" width="340" x="480" y="336" as="geometry" />
</mxCell>
<mxCell id="19" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#ffffff;strokeColor=#ec4899;fontColor=#9d174d;fontSize=13;fontStyle=1;align=left;spacingLeft=15;" value="图形图像处理" vertex="1">
<mxGeometry height="36" width="165" x="480" y="380" as="geometry" />
</mxCell>
<mxCell id="20" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#ffffff;strokeColor=#ec4899;fontColor=#9d174d;fontSize=13;fontStyle=1;align=left;spacingLeft=15;" value="编译器 / 虚拟机开发" vertex="1">
<mxGeometry height="36" width="165" x="655" y="380" as="geometry" />
</mxCell>
<mxCell id="21" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fef3c7;strokeColor=#f59e0b;strokeWidth=2;" value="" vertex="1">
<mxGeometry height="190" width="780" x="60" y="460" as="geometry" />
</mxCell>
<mxCell id="22" parent="1" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#f59e0b;strokeColor=#d97706;fontColor=#ffffff;fontStyle=1;fontSize=16;verticalAlign=middle;" value="💡 选择原则" vertex="1">
<mxGeometry height="40" width="780" x="60" y="460" as="geometry" />
</mxCell>
<mxCell id="23" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dbeafe;strokeColor=#3b82f6;strokeWidth=2;" value="" vertex="1">
<mxGeometry height="115" width="360" x="80" y="515" as="geometry" />
</mxCell>
<mxCell id="24" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;fontSize=14;fontColor=#1e40af;fontStyle=1;" value="追求" vertex="1">
<mxGeometry height="30" width="40" x="100" y="525" as="geometry" />
</mxCell>
<mxCell id="25" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#3b82f6;strokeColor=#2563eb;fontColor=#ffffff;fontSize=12;fontStyle=1;" value="开发效率" vertex="1">
<mxGeometry height="26" width="75" x="145" y="528" as="geometry" />
</mxCell>
<mxCell id="26" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#3b82f6;strokeColor=#2563eb;fontColor=#ffffff;fontSize=12;fontStyle=1;" value="团队协作" vertex="1">
<mxGeometry height="26" width="75" x="230" y="528" as="geometry" />
</mxCell>
<mxCell id="27" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#3b82f6;strokeColor=#2563eb;fontColor=#ffffff;fontSize=12;fontStyle=1;" value="快速迭代" vertex="1">
<mxGeometry height="26" width="75" x="315" y="528" as="geometry" />
</mxCell>
<mxCell id="28" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;fontSize=24;fontColor=#1e40af;fontStyle=1;" value="→" vertex="1">
<mxGeometry height="30" width="40" x="170" y="560" as="geometry" />
</mxCell>
<mxCell id="29" parent="1" style="ellipse;whiteSpace=wrap;html=1;fillColor=#22c55e;strokeColor=#16a34a;fontColor=#ffffff;fontSize=18;fontStyle=1;" value="Java" vertex="1">
<mxGeometry height="55" width="100" x="260" y="560" as="geometry" />
</mxCell>
<mxCell id="30" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fce7f3;strokeColor=#ec4899;strokeWidth=2;" value="" vertex="1">
<mxGeometry height="115" width="360" x="460" y="515" as="geometry" />
</mxCell>
<mxCell id="31" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;fontSize=14;fontColor=#9d174d;fontStyle=1;" value="追求" vertex="1">
<mxGeometry height="30" width="40" x="480" y="525" as="geometry" />
</mxCell>
<mxCell id="32" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#ec4899;strokeColor=#db2777;fontColor=#ffffff;fontSize=12;fontStyle=1;" value="极致性能" vertex="1">
<mxGeometry height="26" width="75" x="525" y="528" as="geometry" />
</mxCell>
<mxCell id="33" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#ec4899;strokeColor=#db2777;fontColor=#ffffff;fontSize=12;fontStyle=1;" value="底层控制" vertex="1">
<mxGeometry height="26" width="75" x="610" y="528" as="geometry" />
</mxCell>
<mxCell id="34" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#ec4899;strokeColor=#db2777;fontColor=#ffffff;fontSize=12;fontStyle=1;" value="资源受限" vertex="1">
<mxGeometry height="26" width="75" x="695" y="528" as="geometry" />
</mxCell>
<mxCell id="35" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;fontSize=24;fontColor=#9d174d;fontStyle=1;" value="→" vertex="1">
<mxGeometry height="30" width="40" x="550" y="560" as="geometry" />
</mxCell>
<mxCell id="36" parent="1" style="ellipse;whiteSpace=wrap;html=1;fillColor=#ef4444;strokeColor=#dc2626;fontColor=#ffffff;fontSize=18;fontStyle=1;" value="C++" vertex="1">
<mxGeometry height="55" width="100" x="640" y="560" as="geometry" />
</mxCell>
<mxCell id="37" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;fontSize=20;fontColor=#3b82f6;fontStyle=1;" value="•" vertex="1">
<mxGeometry height="36" width="25" x="60" y="155" as="geometry" />
</mxCell>
<mxCell id="38" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;fontSize=20;fontColor=#3b82f6;fontStyle=1;" value="•" vertex="1">
<mxGeometry height="36" width="25" x="60" y="199" as="geometry" />
</mxCell>
<mxCell id="39" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;fontSize=20;fontColor=#3b82f6;fontStyle=1;" value="•" vertex="1">
<mxGeometry height="36" width="25" x="60" y="243" as="geometry" />
</mxCell>
<mxCell id="40" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;fontSize=20;fontColor=#3b82f6;fontStyle=1;" value="•" vertex="1">
<mxGeometry height="36" width="25" x="60" y="287" as="geometry" />
</mxCell>
<mxCell id="41" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;fontSize=20;fontColor=#3b82f6;fontStyle=1;" value="•" vertex="1">
<mxGeometry height="36" width="25" x="60" y="331" as="geometry" />
</mxCell>
<mxCell id="42" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;fontSize=20;fontColor=#3b82f6;fontStyle=1;" value="•" vertex="1">
<mxGeometry height="36" width="25" x="60" y="375" as="geometry" />
</mxCell>
<mxCell id="43" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;fontSize=20;fontColor=#ec4899;fontStyle=1;" value="•" vertex="1">
<mxGeometry height="36" width="25" x="460" y="155" as="geometry" />
</mxCell>
<mxCell id="44" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;fontSize=20;fontColor=#ec4899;fontStyle=1;" value="•" vertex="1">
<mxGeometry height="36" width="25" x="460" y="199" as="geometry" />
</mxCell>
<mxCell id="45" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;fontSize=20;fontColor=#ec4899;fontStyle=1;" value="•" vertex="1">
<mxGeometry height="36" width="25" x="460" y="243" as="geometry" />
</mxCell>
<mxCell id="46" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;fontSize=20;fontColor=#ec4899;fontStyle=1;" value="•" vertex="1">
<mxGeometry height="36" width="25" x="460" y="287" as="geometry" />
</mxCell>
<mxCell id="47" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;fontSize=20;fontColor=#ec4899;fontStyle=1;" value="•" vertex="1">
<mxGeometry height="36" width="25" x="460" y="331" as="geometry" />
</mxCell>
<mxCell id="48" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;fontSize=20;fontColor=#ec4899;fontStyle=1;" value="•" vertex="1">
<mxGeometry height="36" width="25" x="460" y="375" as="geometry" />
</mxCell>
<mxCell id="49" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;fontSize=20;fontColor=#ec4899;fontStyle=1;" value="•" vertex="1">
<mxGeometry height="36" width="25" x="635" y="375" as="geometry" />
</mxCell>
</root>
</mxGraphModel>
</diagram>
</mxfile>
五、总结
<mxfile>
<diagram id="java-platform-overview" name="Java 平台概述">
<mxGraphModel dx="1665" dy="798" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="900" pageHeight="750" math="0" shadow="0">
<root>
<mxCell id="0" />
<mxCell id="1" parent="0" />
<mxCell id="2" parent="1" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#1e40af;strokeColor=#1e40af;fontColor=#ffffff;fontStyle=1;fontSize=22;verticalAlign=middle;" value="Java 平台概述 - 核心要点" vertex="1">
<mxGeometry height="55" width="820" x="40" y="20" as="geometry" />
</mxCell>
<mxCell id="3" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#f8fafc;strokeColor=#e2e8f0;strokeWidth=2;" value="" vertex="1">
<mxGeometry height="640" width="840" x="30" y="80" as="geometry" />
</mxCell>
<mxCell id="4" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dbeafe;strokeColor=#3b82f6;strokeWidth=2;" value="" vertex="1">
<mxGeometry height="120" width="780" x="60" y="105" as="geometry" />
</mxCell>
<mxCell id="5" parent="1" style="text;html=1;strokeColor=none;fillColor=#3b82f6;align=center;verticalAlign=middle;fontSize=16;fontStyle=1;fontColor=#ffffff;rounded=1;" value="🎯 核心特性" vertex="1">
<mxGeometry height="35" width="120" x="80" y="115" as="geometry" />
</mxCell>
<mxCell id="6" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#ffffff;strokeColor=#3b82f6;fontColor=#1e40af;fontSize=13;fontStyle=1;" value="面向对象" vertex="1">
<mxGeometry height="40" width="100" x="80" y="165" as="geometry" />
</mxCell>
<mxCell id="7" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#ffffff;strokeColor=#3b82f6;fontColor=#1e40af;fontSize=13;fontStyle=1;" value="跨平台" vertex="1">
<mxGeometry height="40" width="100" x="200" y="165" as="geometry" />
</mxCell>
<mxCell id="8" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#ffffff;strokeColor=#3b82f6;fontColor=#1e40af;fontSize=13;fontStyle=1;" value="自动GC" vertex="1">
<mxGeometry height="40" width="100" x="320" y="165" as="geometry" />
</mxCell>
<mxCell id="9" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#ffffff;strokeColor=#3b82f6;fontColor=#1e40af;fontSize=13;fontStyle=1;" value="多线程" vertex="1">
<mxGeometry height="40" width="100" x="440" y="165" as="geometry" />
</mxCell>
<mxCell id="10" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#ffffff;strokeColor=#3b82f6;fontColor=#1e40af;fontSize=13;fontStyle=1;" value="安全性" vertex="1">
<mxGeometry height="40" width="100" x="560" y="165" as="geometry" />
</mxCell>
<mxCell id="11" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#ffffff;strokeColor=#3b82f6;fontColor=#1e40af;fontSize=13;fontStyle=1;" value="JIT高性能" vertex="1">
<mxGeometry height="40" width="100" x="680" y="165" as="geometry" />
</mxCell>
<mxCell id="12" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dcfce7;strokeColor=#22c55e;strokeWidth=2;" value="" vertex="1">
<mxGeometry height="115" width="780" x="60" y="240" as="geometry" />
</mxCell>
<mxCell id="13" parent="1" style="text;html=1;strokeColor=none;fillColor=#22c55e;align=center;verticalAlign=middle;fontSize=16;fontStyle=1;fontColor=#ffffff;rounded=1;" value="📦 平台版本" vertex="1">
<mxGeometry height="35" width="120" x="80" y="250" as="geometry" />
</mxCell>
<mxCell id="14" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#22c55e;strokeColor=#16a34a;fontColor=#ffffff;fontSize=14;fontStyle=1;" value="SE
标准版" vertex="1">
<mxGeometry height="45" width="90" x="80" y="295" as="geometry" />
</mxCell>
<mxCell id="15" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;fontSize=12;fontColor=#166534;fontStyle=2;" value="基础" vertex="1">
<mxGeometry height="25" width="40" x="180" y="305" as="geometry" />
</mxCell>
<mxCell id="16" edge="1" parent="1" source="14" style="edgeStyle=orthogonalEdgeStyle;strokeColor=#16a34a;strokeWidth=2;endArrow=classic;endSize=10;" target="17">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="17" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#f59e0b;strokeColor=#d97706;fontColor=#ffffff;fontSize=14;fontStyle=1;" value="EE
企业版" vertex="1">
<mxGeometry height="45" width="90" x="230" y="295" as="geometry" />
</mxCell>
<mxCell id="18" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;fontSize=13;fontColor=#166534;fontStyle=1;" value="现代开发:" vertex="1">
<mxGeometry height="25" width="80" x="380" y="305" as="geometry" />
</mxCell>
<mxCell id="19" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#166534;strokeColor=#14532d;fontColor=#ffffff;fontSize=13;fontStyle=1;" value="SE + Spring Boot" vertex="1">
<mxGeometry height="35" width="140" x="460" y="300" as="geometry" />
</mxCell>
<mxCell id="20" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;fontSize=13;fontColor=#166534;fontStyle=1;" value="为主流选择 ⭐" vertex="1">
<mxGeometry height="25" width="110" x="610" y="305" as="geometry" />
</mxCell>
<mxCell id="21" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fef3c7;strokeColor=#f59e0b;strokeWidth=2;" value="" vertex="1">
<mxGeometry height="115" width="780" x="60" y="370" as="geometry" />
</mxCell>
<mxCell id="22" parent="1" style="text;html=1;strokeColor=none;fillColor=#f59e0b;align=center;verticalAlign=middle;fontSize=16;fontStyle=1;fontColor=#ffffff;rounded=1;" value="🔄 vs C++" vertex="1">
<mxGeometry height="35" width="100" x="80" y="380" as="geometry" />
</mxCell>
<mxCell id="23" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dbeafe;strokeColor=#3b82f6;strokeWidth=1;" value="" vertex="1">
<mxGeometry height="45" width="350" x="80" y="425" as="geometry" />
</mxCell>
<mxCell id="24" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#3b82f6;strokeColor=#2563eb;fontColor=#ffffff;fontSize=13;fontStyle=1;" value="Java" vertex="1">
<mxGeometry height="30" width="60" x="90" y="432" as="geometry" />
</mxCell>
<mxCell id="25" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;fontSize=12;fontColor=#1e40af;fontStyle=0;" value="简单安全,自动内存管理,开发效率高" vertex="1">
<mxGeometry height="30" width="260" x="160" y="432" as="geometry" />
</mxCell>
<mxCell id="26" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fce7f3;strokeColor=#ec4899;strokeWidth=1;" value="" vertex="1">
<mxGeometry height="45" width="370" x="450" y="425" as="geometry" />
</mxCell>
<mxCell id="27" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#ec4899;strokeColor=#db2777;fontColor=#ffffff;fontSize=13;fontStyle=1;" value="C++" vertex="1">
<mxGeometry height="30" width="60" x="460" y="432" as="geometry" />
</mxCell>
<mxCell id="28" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;fontSize=12;fontColor=#9d174d;fontStyle=0;" value="极致性能,底层控制,适合系统级开发" vertex="1">
<mxGeometry height="30" width="280" x="530" y="432" as="geometry" />
</mxCell>
<mxCell id="29" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#ede9fe;strokeColor=#8b5cf6;strokeWidth=2;" value="" vertex="1">
<mxGeometry height="200" width="780" x="60" y="500" as="geometry" />
</mxCell>
<mxCell id="30" parent="1" style="text;html=1;strokeColor=none;fillColor=#8b5cf6;align=center;verticalAlign=middle;fontSize=16;fontStyle=1;fontColor=#ffffff;rounded=1;" value="💡 Java 真正竞争力" vertex="1">
<mxGeometry height="35" width="170" x="80" y="510" as="geometry" />
</mxCell>
<mxCell id="31" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;fontSize=15;fontColor=#5b21b6;fontStyle=0;" value="不是跨平台,而是" vertex="1">
<mxGeometry height="30" width="140" x="80" y="555" as="geometry" />
</mxCell>
<mxCell id="32" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#8b5cf6;strokeColor=#7c3aed;fontColor=#ffffff;fontSize=16;fontStyle=1;" value="庞大成熟的生态系统" vertex="1">
<mxGeometry height="40" width="200" x="220" y="550" as="geometry" />
</mxCell>
<mxCell id="33" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#22c55e;strokeColor=#16a34a;fontColor=#ffffff;fontSize=13;fontStyle=1;" value="Spring" vertex="1">
<mxGeometry height="35" width="100" x="80" y="610" as="geometry" />
</mxCell>
<mxCell id="34" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#3b82f6;strokeColor=#2563eb;fontColor=#ffffff;fontSize=13;fontStyle=1;" value="MyBatis" vertex="1">
<mxGeometry height="35" width="100" x="195" y="610" as="geometry" />
</mxCell>
<mxCell id="35" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#f59e0b;strokeColor=#d97706;fontColor=#ffffff;fontSize=13;fontStyle=1;" value="Kafka" vertex="1">
<mxGeometry height="35" width="100" x="310" y="610" as="geometry" />
</mxCell>
<mxCell id="36" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#ec4899;strokeColor=#db2777;fontColor=#ffffff;fontSize=13;fontStyle=1;" value="Hadoop" vertex="1">
<mxGeometry height="35" width="100" x="425" y="610" as="geometry" />
</mxCell>
<mxCell id="37" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#06b6d4;strokeColor=#0891b2;fontColor=#ffffff;fontSize=13;fontStyle=1;" value="Elasticsearch" vertex="1">
<mxGeometry height="35" width="100" x="540" y="610" as="geometry" />
</mxCell>
<mxCell id="38" parent="1" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#64748b;strokeColor=#475569;fontColor=#ffffff;fontSize=13;fontStyle=1;" value="..." vertex="1">
<mxGeometry height="35" width="50" x="655" y="610" as="geometry" />
</mxCell>
<mxCell id="39" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;fontSize=14;fontColor=#5b21b6;fontStyle=2;" value="丰富的框架和工具" vertex="1">
<mxGeometry height="30" width="150" x="80" y="655" as="geometry" />
</mxCell>
<mxCell id="40" parent="1" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;fontSize=28;" value="🚀" vertex="1">
<mxGeometry height="35" width="50" x="720" y="610" as="geometry" />
</mxCell>
</root>
</mxGraphModel>
</diagram>
</mxfile>
💬 评论